cost 155 ms
在 C++ 中,有沒有一種方法可以在調用者不使用命名變量的情況下使用 std::stringstream& 參數調用 function?

[英]In C++ is there a way to call a function with a std::stringstream& argument without the caller using a named variable?

在 C++ 中,是否可以調用參數為 std::stringstream& 的 function 而無需調用方聲明類型為 std::stringstream 的顯式命名變量? 即我想完成一些類似的事情: 上面的代碼產生了這個編譯錯誤: (我不確定我是否正確理解了這個問題——我認為這是因為c ...

使用 stringstream 解析 function 是如何工作的?

[英]How does this parsing function using stringstream work?

所以我做了一個 function 來在上學期的陰霾中用逗號分隔符解析給定的字符串。 很可能我從在線指南中獲取了很多內容,但它適用於整個項目,所以我做到了。 現在我回去審查它,我很困惑。 這是代碼 `vector parsedString(string line){ vector splitStri ...

在 stringstream 中使用 fixed 和 setprecision 時出現 C++ 的舍入錯誤

[英]round error of C++ when using fixed and setprecision in stringstream

我在C++寫了一個程序,我想它的結果應該是12.3和12.2。 但是最后的結果是12.2和12.2。 顯然,它沒有正確舍入。 但為什么? 非常感謝你:) 我還嘗試了 num1 = 12.05 和 num2 = 12.04 的方式,並獲得了 12.1 和 12.0 的預期結果。 ...

使用`ostream`流入`char`數組-如何獲取寫入的字符數?

[英]Streaming into `char` array with `ostream` - how to get characters written count?

這個答案顯示了如何使用stringstream寫入數組,但是我們可以獲得寫入的字符總數嗎? 當然, stringstream流有一些信息可以知道將下一個字符放在哪里,但我不知道如何訪問它。 鏈接問題的 OP 甚至在評論中提出這個問題,但我想確定一個單獨的問題。 我知道ostrstream有一個pc ...

basic_stringstream 及其父類

[英]basic_stringstream and its parent classes

為什么basic_stringstream派生自basic_iostream而不是basic_istringstream和basic_ostringstream ? 那么從basic_istringstream和basic_ostringstream得到什么? 參考 ...

如何在字符串流中格式化填充的有符號數字

[英]How to format padded signed numbers in a stringstream

我正在嘗試使用 C++ 流來格式化數字,並且在將符號字符放置在填充之后而不是之前遇到問題。 當我這樣做時: output 是 但我想要的是 使用 printf,我可以使用像“%06d”這樣的格式,它的工作方式與我期望的將符號放在零之前一樣,但我想在 stream 中獲得相同的效果,而不是使用舊的格 ...

嘗試將內容插入向量后,為什么我的字符串流會充滿垃圾?

[英]Why does my stringstream get filled with garbage after tryng to insert the contents into a vector?

考慮代碼: gid_list的聲明為: std::string gid_list; ,內容為: 因此,我將將字符串流值插入向量中的代碼行注釋掉了,打印的值是正確的,但是一旦我取消注釋這些行,字符串流的打印值就會出現亂碼,並且似乎充滿了隨機的東西。 我知道字符串流可能很挑剔,但最令人困惑的部分是 ...

將字符串流放在另一個的開頭

[英]Putting a stringstream at the beginning of another

我將信息放在stringstream中,但在它的最后,只是添加了一些東西。 但是我現在需要在要添加內容的開頭添加一些內容。 例子:std::stringstream stream; string a = "123"; string b = "456"; ss << a; ss <& ...

如何將 char16_t 轉換為按 2 個字節划分的字符串流

[英]How to convert a char16_t into a stringstream divided with 2 bytes

我做了一個 utf8 到 utf16 的轉換,我得到了 utf16 char16_t 的代碼單元。 Output: 如果可能,我現在需要將代碼單元傳遞給字符串流,但我不知道如何將其轉換為 2 個字節,如下所示: 有什么建議么? 也許首先將其轉換為 uint8_t 向量? ...

套接字寫入 for 循環混合字符串緩沖區

[英]socket write in for loop mixes string buffers

我使用這樣的 for 循環多次調用一個函數: home_axis()函數定義為: 並且controller.Write()函數只是標准write(2)的包裝器,它將字符串中的字符寫入套接字文件描述符。 您可以看到,每次調用home_axis()時,它都應該有自己的、新鮮的std::str ...

C++ 標准是否保證當“rdbuf”的返回值傳遞給流輸出運算符時,緩沖區的內容被打印出來

[英]Does the C++ standard guarantee that when the return value of 'rdbuf' passed to the stream output operator, he conent of the buffer gets printed out

考慮以下代碼片段: 變量a是指向std::stringbuf類型對象的指針。 當它通過 GCC9.4 傳遞給流輸出運算符<<時,將打印出a指向的流緩沖區的內容。 我的問題是:這種行為只是在 GCC 中實現std::stringbuf的方式造成的意外,還是語言標准保證這將始終有效? ...

關於C++中std::string類型到模板T類型的轉換

[英]On the conversion from std::string type to template T type in C++

我在這個論壇上發現了以下由用戶 Ben Voigt 編寫的片段: 我正在尋找一種方法來處理convert >> value; . 我的目標是迭代對用戶的請求,使其正確插入給定的輸入: 我的想法是在getline_as中創建一個do-while循環,但我無法讓它工作。 ...

std::stringstream 的 seekg 在 while 循環后不起作用

[英]std::stringstream's seekg does not work after while loop

我有這個std::stringstream object 其內容我必須(只)閱讀兩次。 為此,我想我可以使用它的seekg成員 function 來重復閱讀。 但我無法讓它發揮作用。 這是一個重現我遇到的問題的 MWE(改編自文檔中的示例)。#include <iostream> #in ...

如何防止C++ string stream將double讀入int?

[英]How to prevent C++ string stream from reading double into int?

我想寫一個 function 從字符串中讀取 integer 並在遇到無效輸入時拋出錯誤。 無效輸入包括非數字和非整數輸入。 以下 function 將非數字輸入檢測為無效輸入,但不處理雙輸入。 因為讀入 int 只會抓取數字,當它到達“。”時。 它停止閱讀。 因此,如果用戶通過“1.5”,下面的 ...

如何從 txt 文件中提取帶逗號分隔符的字符串,並將逗號分隔符分隔的每個元素解析為 class 構造函數

[英]How to extract string with comma delimiter from txt file and parse every element separete by comma delimiter into a class constructor

來源:文本文件存儲帳戶信息列表。 例如:10041249,Mr,Vincent,Rogan,Rogan Locksmiths Ltd,Nell,5287.000000,,491.691000, 10021250,Mrs,Adele,Cunningham,Cunningham Demolition L ...


 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM