istringstream

    0熱度

    1回答

    我做的這個問題: https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/ 我的方法是序列化的字符串分配給像 「1#,2#,#」 流。 然後從流中讀取一個字符。如果它是'#',則返回。否則, 訪問左側和右側的孩子。 class Solution { stringstream pre; int

    -1熱度

    3回答

    我正在編寫一個程序,以將用戶輸入的句子與文件中的單詞進行比較。我想讓程序告訴我,如果在文件中找到了句子中的任何單詞。 我使用getline獲取用戶輸入的句子,然後我使用istringstream將句子分成單詞並將每個單詞與文件中的每個單詞進行比較。我的方法是使用while循環遍歷文件中的每個單詞,並將用戶輸入句子中的當前單詞與文件中的當前單詞進行比較。如果當前文件詞與當前句子詞相同,那麼我將設置一

    0熱度

    2回答

    我注意到,當我使用istringstream時,即使整個字符串被「消耗」,eof()也不會返回true。例如: char ch; istringstream ss{ "0" }; ss >> ch; cout << ss.peek() << " " << (ss.eof() ? "true" : "false"); 輸出(VS2015): -1 false

    -1熱度

    1回答

    我使用stringstream來解析配置文件。 C++整型變量在分配文本文件中的值時工作正常。但是,當我將配置文件中的讀取值分配給C++ int16_t變量時,它只是分配一個不同的值。我不知道發生了什麼事。 這是我的代碼: void parseConfigurationFile(){ //Variables int16_t int16_tValue; int firs

    -1熱度

    2回答

    程序應該將輸入數字的字符串和數字分隔符作爲輸入,並將4個單詞輸出到單獨的行中。 例 Please enter a digit infused string to explode: You7only7live7once Please enter the digit delimiter: 7 The 1st word is: You The 2nd word is: only The 3rd

    4熱度

    1回答

    文件(SETTINGS.TXT)的端部不讀新行的文件內容進行解析: FULLSCREEN=On V_SYNC=On [no "\n" at the end of file] 萬一沒有ENTER「\ n」個輸出是: MapKey= FULLSCREEN MapValue= On MapKey= V_SYNC MapValue= Onřřřř 隨着ENTER「\ n」的文件輸出的到底是正

    0熱度

    1回答

    可惜this沒有任何幫助...... 我有拋出作爲實現異常的軟件,但我需要知道如何避免它。以下是具體部分: if (!(iss >> c)) { throw std::runtime_error( "No return code: status line doesn't begin with return code"); } 這是整個方法。 void parseReply

    0熱度

    1回答

    #include <iostream> #include <string> #include <sstream> int main() { std::istringstream iss; iss.str("[email protected]"); double result; iss >> result; std::cout << resu

    1熱度

    2回答

    我正在尋找一個簡單和優雅的方式來解析數字(十進制和十六進制)stringstream(或istringstream或一些其他的Std-C++類)。 有效輸入的十進制數例如11應該是 0XB BH 通常我會使用一個正則表達式,但它是不可能的,因爲這裏缺少庫和奧得C++編譯器。 謝謝!

    0熱度

    2回答

    我想創建一個vector <int>其大小沒有預先定義。只要輸入終端中有數字,就應該輸入數字,當我點擊Enter時應該停止讀數。我嘗試了很多解決方案,其中包括here和here。在第二種情況下,我可以輸入一個非整數來終止向量的輸入。如果我使用第一個解決方案(下面添加的代碼),它將無限期地監聽輸入。 代碼: #include <iostream> #include <vector> #inclu