错误 C2679:二进制“<<": 没有找到使用“std::string"类型的右侧操作数的运算符

2022-01-04 00:00:00 string operators io c++

代码:

    #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>

相关文章