#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> svec;
string str;
while (str != NULL)
{
cin >> str;
svec.push_back(str);
}
cout << str[0];
cout << str[1];
cout << str[2];
return 0;
}
svec.cpp
C:\Work\svec\svec.cpp(12) : error C2676: binary '!=' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Work\svec\svec.cpp(12) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
错误的原因是什么? 怎么改?
str不是指针,只有指针才能使用!=NULL,可参考改为如下(ctrl+z结束):
#include <iostream>