getline

    2熱度

    2回答

    爲什麼cin.getline開始爲身體輸入的第二行工作,但打破了第一行? 範例程序運行: Enter name: Will Enter body: hello world hello again <= It accepts this one char* name = new char[100]; char* body = new char[500]; std::cout << "

    0熱度

    4回答

    我有一個問題,但我無法弄清楚我做錯了什麼。我不確定這是否是我的循環出現問題,或者cin緩衝區未被清除。我正在做一個將C風格的字符串轉換爲大寫字母的程序,但是如果用戶輸入的字符數超過了11個,那麼該函數應該只顯示前11個字符,之後的任何內容都不應該顯示。問題是,如果我輸入超過11個字符,然後我的循環從不停止,並不斷告訴用戶輸入的答案無效,並且他是否要輸入新的字符串。

    1熱度

    2回答

    我最初構建了一個類似索引的機制,使用getline讀取文本文件的每一行,檢查它是否匹配已知的頭聲明(string.compare)並將tellg位置保存爲指向那個點。 然後我的意圖是使用seekg(index,ios :: beg)來尋找頭文件所在文件的位置。 在構建我的索引並調用seekg(0,ios :: beg)時,通過一次文件讀取後,下一個getline返回一個空字符串,我希望看到文件中的

    6熱度

    7回答

    是否有一種簡單的方法來檢查行是否爲空。所以我想檢查它是否包含任何空格,如\ r \ n \ t和空格。 感謝

    15熱度

    3回答

    是否有可能通過您在Eclipse中輸入到逆時針REPL中的歷史記錄?就像按下向上箭頭或ctrl-p或其他各種可以在其他repl中工作的東西一樣? 謝謝! -Philip

    1熱度

    4回答

    #include "keywords.h" #include <iostream> #include <fstream> #include "llist.h" #include <string> using namespace std; //default constructor List<string> L; keywords::keywords(){ } void key

    2熱度

    3回答

    這是我的主要程序, int main() { string command; cin>>command; if(command == "keyword") { string str, str2, str3, str4; cout << "Enter first name: "; getline (cin,str);

    0熱度

    3回答

    我能夠寫入文本文件,然後使用getline,我不能再寫入文件。 #include <iostream> #include <fstream> #include <string> using namespace std; int main(){ ifstream infile; fstream crypto; ofstream hacker; string tempString;

    2熱度

    2回答

    這是一個很奇怪的問題,當我的程序會詢問用戶的地址,而不是等待輸入跳過函數getline(),它似乎跳過函數getline()函數完全 Answerinput: cout << "would you like to add another entry to the archive? (Y/N):"; cin >> answer; cout << endl; cout << endl;

    5熱度

    3回答

    我很好奇cin.getline和global getline函數在不同的地方的技術原因。 什麼是不簡單地定義爲所有這些CIN函數簽名的動機: //THESE TWO EXIST istream& cin::getline (char* s, streamsize n); istream& cin::getline (char* s, streamsize n, char delim); /