错误 C2679:二进制'<<':找不到采用类型为"std::string"的右侧操作数的运算符
error C2679: binary '<<' : no operator found which takes a right-hand operand of type “std::string”
代码:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
int main()
{
ifstream fin ("ride.in.txt");
ofstream fout ("ride.out.txt");
int ta, tb;unsigned int i;
ta = tb = 1;
string a, b;
fin >> a >> b;
for (i = 0; i < a.size(); i++)
ta = ta * (a[i] - 'A' + 1) % 47;
for (i = 0; i < b.size(); i++)
tb = tb * (b[i] - 'A' + 1) % 47;
if (ta == tb)
fout << "GO" << endl;
else
fout << "STAY" << endl;
return 0;
}
错误:
error C2679:
binary '<<' : no operator found which takes a right-hand operand of type “std::string”
我认为问题是:
#include <string.h>
更改为:
#include <string>
std::string
运算符在 <string>
标头中定义。
标头<string.h>
用于 C 样式的字符串函数。
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- cppcheck在const std::string[]上引发警告
- 将std::string传递给WriteConsole API
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 为std::string的某个索引赋值
- <<操作员在下面的行中工作
- std中有类似find_last_of的函数,而string中没有
- 使用 std::string () const 函数启动线程或未来
- 使用char类型将decimal转换为string,将string转换为decimal
- 迭代和比较映射<字符串、矢量<string>> c++ 中的值
- 当我们进行一些操作时,应该使用什么'std::string'或'std::stringstream'?
- 将向量解析<string>为字符串
- 'string.assign(string.data(), 5)' 是明确定义的还是 UB?
- 如何更改大小(std::string)
- "string.h"在构建适用于iOS的qt应用程序中找不到消息
- C++:如何将 unix 时间的字符串转换为 *tm?(使用时间错误:"cannot convert 'String' to 'tm*' ")
- std::string 的对象真的可以移动吗?
- 与'operator='不匹配(操作数类型'String'且"void")
- SegFault 同时使用 std::string::operator+= 和函数作为参数