c – 错误C2679:二进制’<<':找不到运算符,它接受类型为“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>
上一篇:c – 多输出运算符?


下一篇:Python中的新运算符