错误C2679:二进制'<<' :没有找到哪个运算符采用“std :: string”类型的右手操作数

时间:2011-12-30 12:32:40

标签: c++ string io operators

代码:

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

2 个答案:

答案 0 :(得分:17)

我认为问题是:

#include <string.h>

更改为:

#include <string>

答案 1 :(得分:5)

std::string运算符在<string>标头中定义。

标题<string.h>用于C风格的字符串函数。