2011-12-30 60 views
-1

代碼的右手操作數:錯誤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」 
+1

毫無疑問,代碼編譯(當刪除未提供的預編譯頭部時)在叮噹中。 – Andre 2011-12-30 12:49:06

+2

它會在任何編譯器上進行編譯,這些編譯器的庫*發生*包括''或''中的''。一個C++標準頭允許包含任何其他標準頭。 – 2011-12-30 14:56:24

回答

15

我想問題是:

#include <string.h> 

變化:

#include <string> 
5

std::string運算符在<string>標題中定義。

標題<string.h>用於C風格的字符串函數。

相關問題