2016-07-06 145 views
0

你好,我正在爲我的C++類做這個項目,而且我的代碼有問題。我不知道是否應該發佈整個代碼,因爲它很長,但是我只是要發佈函數以及錯誤的位置。錯誤 - 函數調用不正確?

這裏是功能 -

void loadfile(int jeff[][4],int anna[][4]) 

{ 
string fname; 
cout<< "Enter the name of the file to load:" << endl; 
cin>>fname; 
ifstream istream(fname); 
if(istream.is_open()) 
{ 
     for(int i=0;i<2;i++) 
     { 
      if(i==0) 
      { 
       for(int j=0;j<4;j++) 
       { 
        for(int k=0;k<4;k++) 
        { 
         istream>>jeff[j][k]; 
        } 
       } 
      } 
      else 
      { 
       for(int j=0;j<4;j++) 
       { 
        for(int k=0;k<4;k++) 
        { 
         istream>>anna[j][k]; 
        } 
       } 
      } 
     } 
     cout<<"New shcedule loaded successfully" << endl; 
} 
else 
{ 
     cout<<"Error in opening file" << endl; 
     return; 
} 
} 

我在

ifstream istream(fname); 

錯誤得到一個錯誤說 - 錯誤:呼叫沒有匹配功能

這裏是我的電話

case '6': 
    loadfile(jeff, anna); 
    break; 
+0

使用'ifstream istream(fname.c_str());'。或使用現代編譯器 –

+0

'istream'是在'std'名稱空間下定義的類型 –

+0

@UchiaItachi使用'istream'作爲變量名也是合法的,儘管不是一個好主意 –

回答

0

更改th e行你得到的錯誤在

ifstream istream(fname.c_str()); 

它看起來像你的編譯器是在C + + 98/03模式。在這種情況下,打開文件的std::ifstream構造函數需要const char*。直到C++ 11纔會添加採用const std::string&的構造函數。