getline

    25熱度

    4回答

    我有一個使用getline()讀取文件中每一行的循環。 istream is; string line; while (!getline(is, line).eof()) { } 我注意到,調用函數getline()這樣也似乎工作: while (getline(is, line)) 這是怎麼回事? getline()返回一個流引用。它以某種方式被轉換爲指針嗎?這實際上是一種好的做

    5熱度

    2回答

    我有這樣的代碼, int main() { std::string st; std::stringstream ss; ss<<"hej hej med dig"<<std::endl; std::getline(ss,st,' '); std::cout <<"ss.rdbuf()->str() : " << ss.rdbuf()->str(

    3熱度

    3回答

    首先,我對C++很陌生。我相信getline()不是標準的C函數,所以需要#define _GNU_SOURCE來使用它。現在,我使用C++和g ++告訴我,_GNU_SOURCE已定義: $ g++ -Wall -Werror parser.cpp parser.cpp:1:1: error: "_GNU_SOURCE" redefined <command-line>: error: th

    17熱度

    6回答

    是否有一個原因,如果在我的計劃,我要求用戶輸入的,而我做的事: int number; string str; int accountNumber; cout << "Enter number:"; cin >> number; cout << "Enter name:"; getline(cin, str); cout << "Enter account number:"; c