原始code如下:
1 int id2; 2 std::string label2; 3 std::string line; 4 5 while(getline(file, line)){ 6 label2 = line.substr(5, line.size()); 7 id2 = line.substr(1,4); 8 9 if (id2 == xxx) 10 break; 11 }
提示错误:
cannot convert ‘std::basic_string<char>‘ to ‘int‘ in assignment ...
解决方法:
1 while(getline(file, line)){ 2 label2 = line.substr(5, line.size()); 3 id2 = atoi((line.substr(1,4)).c_str()); 4 5 if (id2 == xxx) 6 break; 7 }
参考网址:http://www.cplusplus.com/forum/general/13135/
原文:http://www.cnblogs.com/wangxiaocvpr/p/4937524.html