2013-07-16 75 views
0
#include<iostream> 
#include <string.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include<fstream> 
#include<string> 

using namespace std; 

    int countLines(ifstream& in ) 
    { 
     int count = 0; 
     char line[80]; 
     if (in.good()) 
     { 
      //while (!feof(in)) 
       while(getline(in,line)) count++; 
      in.seekg(ios::beg); 
     } 
     return count; 
    } 

沒有匹配的調用函數獲取線 這是什麼意思? 我已經包含了所有的標題,但爲什麼我仍然無法調用get line?Getline error undefined

+0

的文檔查找一個'的std :: getline'參考,並尋找示例代碼和參數。將參數類型與您的參數類型進行比較,並使用示例進行幫助。 – chris

回答

2

您需要使用std :: string而不是字符數組來調用字符串的getline()函數。將char line[80]替換爲std::string line,它將起作用。

入住這裏http://www.cplusplus.com/reference/string/string/getline/

+0

@salgar我試過#include ,但不能。事實上,當我包含它並使用cout而不是printf時,它會產生另一個錯誤,說cout沒有被定義。我的標題有問題嗎?但我也嘗試過使用Microsoft Visual Studio。 –

+0

是的,你說對不起,修正了答案。 – Salgar

+0

@PramonoWang查看更新的答案 – Salgar

相關問題