C++提问
朋友们,为啥我这个显示i不是左值啊,小白一个,求解{:5_92:}#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::vector;
using namespace std;
int main()
{
vector<string> s{ "a","an"," ","dsaf",".","adsf" };
for (const auto &i : s)
{
cout << i;
if (i.empty() || i = '.')
cout << endl;
else
cout << " " << endl;
}
return 0;
} 你为什么不看错误提示?
main.cpp: In function ‘int main()’:
main.cpp:14:52: error: lvalue required as left operand of assignment
if (i.empty() || i = '.')
^~~
错误提示就是“表达式必须是可修改的左值啊。。”
页:
[1]