[英]no matching function for call to getline()
所以我正在做某事,但我似乎無法理解為什么它不起作用。
void display_alls()
{
ifstream fpd;
fpd.open("student2.txt",ios::in);
if(!fpd)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}
while(fpd)
{
int pos;
string seg;
cout<<"\tUSN"<<setw(10)<<"\tName"<<setw(20)<<"Book Issued\n";
//fp.seekg(pos,ios::beg);
getline(fpd,st.usn,'|');
getline(fpd,st.name,'|');
getline(fpd,st.email,'|');
getline(fpd,st.phone,'|');
getline(fpd,st.stbno,'|');
getline(fpd,seg);
cout<<"\t"<<st.usn<<setw(20)<<st.name<<setw(10)<<st.stbno<<endl;
}
fp.close();
}
[錯誤] D:\\ library \\ library_v1.cpp:514:錯誤:沒有匹配函數調用`getline(std :: ifstream&,char [20],char)'
getline
每一行都有錯誤! 但不在“ getline(fpd,seg);
”中
這個東西在MingW編譯器上不起作用,但是在我的大學系統上工作,idk也許他們使用的是較舊的編譯器,請您告訴我哪里出了問題。 非常感激。
如果您要使用的是std::getline
,則在<string>
標頭中定義。 您將要包括它:
#include <string>
然后您可以通過std::getline
調用它。 如果您厭倦了鍵入std::
,則可以執行以下操作:
using namespace std;
根據IDE或構建設置的不同,有時這些事情可能已經為您完成。 這可能就是為什么它可以在學校計算機上工作,而不是在您的計算機上工作的原因。
錯誤消息表明該代碼正在嘗試讀入20個字符的數組。 不幸的是std::getline
不處理字符數組。 它只會讀入std::string
,這就是為什么它可以與string seg;
一起使用的原因string seg;
對於字符數組,您需要使用std::istream::getline
。 鏈接到文檔頁面
但是,如果可以用std::string
替換數據結構中的字符數組,那么生活可能會更輕松。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.