error C2440: 'initializing' : cannot convert from 'char *' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *'
清泛原创
error C2440: 'initializing' : cannot convert from 'char *' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
//输出一行中所有字符
void printchar(string &line)
{
istringstream iss(line);
string word;
while(iss>>word)
for(vector<string>::const_iterator itbegin=word.begin(),itend=word.end();itbegin != itend; ++itbegin)
cout<<*itbegin<<endl;
}
解决方法:标准库string对象可以使用迭代器操作 ,但是其迭代器要正确使用,应该使用string::const_iterator 后者使用下标操作来获取string对象中的字符。
上一篇:warning C4172: returning address of local variable or temporary
下一篇:fatal error "vector iterator + offset out of range" "standard C++ libraries out of range"