【求助】(str = str2)
#include<iostream>
#include<string>
using namespace std;
int main()
{
int errors=0;
string str("a very long literal string");
for(int ix =0;ix<1000000;++ix)
{
int len =str.size();
string str2=str;
if(str != str2)//为什么如果吧条件改成(str=str2)编译就不通过
++errors;
}
cout<<"string class:"
<<errors<<"errors occurred.\n";
return 0;
}
提示出错如下#include<string>
using namespace std;
int main()
{
int errors=0;
string str("a very long literal string");
for(int ix =0;ix<1000000;++ix)
{
int len =str.size();
string str2=str;
if(str != str2)//为什么如果吧条件改成(str=str2)编译就不通过
++errors;
}
cout<<"string class:"
<<errors<<"errors occurred.\n";
return 0;
}
error C2451: conditional expression of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' is illegal
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
他们不就是一个errors要加,一个errors不加的不同吗?