错误 C2679:二进制'<<':找不到采用类型为"std::string"的右侧操作数的运算符

error C2679: binary '<<' : no operator found which takes a right-hand operand of type “std::string”

本文关键字:lt string std 运算符 操作数 二进制 C2679 找不到 类型 错误      更新时间:2023-10-16

代码:

    #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 样式的字符串函数。