菜鸟问题,不要见笑
#include<iostream>#include<string>
#include<cstring>
void strcount(char *);
int main()
{
using namespace std;
string str;
cout<<"enter...........\n";
getline(cin,str);
while(str!="")
{
strcount(&str);
cout<<"enter!\n";
getline(cin,str);
}
cout<<"*********\n";
return 0;
}
void strcount(char *str)
{
using namespace std;
static int total=0;
int count=0;
while(*str++)
count++;
total+=count;
cout<<count<<endl;
cout<<total<<endl;
}
编译失败,错误为
error C2664: 'strcount' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
xiti92.exe - 1 error(s), 0 warning(s)