2012-02-12 18 views
1

我已經包含並正在使用標準名稱空間,並且程序運行得很好,當我只是將文件名硬編碼進入時,但是當我放入該cin時,VS會給我奇怪的錯誤。 爲了清晰起見,我特別提到了cin >> sodokuFile行。爲什麼這個基本的cin阻止我的程序編譯?

cout << "Assignment 2\n\n"; 
ifstream ins; 
cout << "Please enter the Sokoku file\n"; 
string sodokuFile; 
cin >> sodokuFile; 
ins.open(sodokuFile.c_str()); 

if(ins.is_open()) 
{ 
    int num; 
    //counting numbers displayed horizontally 
    int counth = 0; 
    //counting numbers displayed vertically 
    int countv = 0; 
    while (ins >> num) 
    { 
     cout << num << " "; 
     counth++; 
     //placing vertical lines 
     if(counth %3 == 0) 
     { 
      cout << "| "; 
     } 
     //making line breaks for new rows 
     if(counth == 9) 
     { 
      cout << "\n\n"; 
      counth = 0; 
      countv++; 
      //horizontal lines 
      if(countv %3 == 0) 
      { 

       cout << "_________________________________________\n"; 
      } 
     } 
    } 
} 
else 
{ 
    cout << "File does not exist\n"; 
    return 0; 
} 

return 0 ; 

這裏是在編譯器錯誤的唯一的事情,看起來有用 錯誤C2679:二進制「>>」:沒有運營商發現這需要類型的右手操作數「的std :: string」(或有是沒有可接受的轉換)

+2

你有沒有'#include '? – 2012-02-12 18:59:35

+1

哦,*怪異*錯誤,與普通錯誤相反......也許這是一個編譯器錯誤。如果只是有一種方法來知道這些錯誤是什麼。 – 2012-02-12 19:00:32

+0

第一個錯誤是什麼? – 2012-02-12 19:01:04

回答

6

你需要把

#include <string> 

在你的文件的頂部,因爲string標題聲明operator>>(istream&, string&)

相關問題