cost 349 ms
“清除”std::string_view 的正確方法是什么?

[英]What is the correct way to “clear" a std::string_view?

我看到這篇文章: c++ - 為什么 std::string_view 沒有 assign() 和 clear() 方法? - 堆棧溢出,因此string_view不包含clear的 function。 但在我的例子中,我有一個string_view作為 class 成員變量,有時,我想將它重置 ...

為什么 std::string 將內容存儲在循環內的同一地址?

[英]Why does std::string store content at the same address inside a loop?

我需要動態創建一個 char[] 。 我想使用 std::string 而不是直接處理 char[],因為我不需要使用 std::string 處理 memory 管理。 這是我的示例代碼: output 是: ,這不是我想要的。 在我的理解中,循環內部創建的字符串s在每次迭代中應該都是全新 ...

如何接受c++中未知行數,每行有兩個字符串

[英]How to accept an unknown number of lines in c++, each line has two strings

如何接受 c++ 中的未知行數? 每行有兩個字符串,中間用空格分隔。 我嘗試了This cplusplus forum中提到的解決方案,但沒有一個解決方案對我有用。 只有在每行末尾按下Enter時,其中一種解決方案才有效。 我不確定是否會在輸入行的末尾給出\n字符。 我有哪些選擇? 我目前的嘗試要求 ...

std::string 格式如 sprintf / printf 並且也不允許 arguments

[英]std::string formatting like sprintf / printf and also allow for no arguments

我正在嘗試解決這樣一個問題: std::string formatting like sprintf: std::string formatting like sprintf 然而,我遇到的問題是我想讓它適用於只有常量字符串而沒有額外參數的情況:`string_format("just a str ...

如何將 char* 轉換為 std::u8string?

[英]How to convert char* into std::u8string?

介紹如果我捕獲到異常,我想將錯誤消息(通過what()方法作為 C 風格字符串返回)轉換為std::u8string (UTF-8 字符串)。 例如: std::u8string(error.what()); 問題如何將char*轉換為std::u8string ? 附加信息我只捕獲來自標准庫、b ...

如何在沒有調試信息的情況下獲取 __malloc_printerr__ 的變量值?

[英]How to get the variable values of __malloc_printerr__ without debug-info?

我有一個 C++ 程序,它使用 gcc4.4.5 編譯並在 redhat 6.1 上運行。 程序用-m64編譯,CPU為Intel-64。 它總是在幾天后(隨機)中止。 由於找不到redhat6.1 的debug-info 文件,我不得不反匯編function malloc_pinterr來嘗試找 ...

將參數包限制為類字符串類型或可轉換為字符串的類型的概念

[英]Concept for constraining parameter pack to string-like types or types convertible to string

我正在拼湊一個 C++20 難題。 這是我想要做的: Function append_params會將 url 與其他查詢參數連接在一起。 為了以動態和可擴展的方式進行設計,我想寫一個這樣的概念它允許可以從中構造 std::string 的類型它允許使用 std::to_string() 將類型轉換 ...

使用 std::enable_if 禁用構造函數

[英]Disabling a constructor using std::enable_if

我的目標是創建我自己的std::basic_string類似物,但有一些附加條件。 我希望我的AnyString<CharType, Traits>可以從std::basic_string<CharType, AnyOtherTraits, AnyAlloc>但我想為某些 C ...

如何為 std::cout 初始化自定義模擬?

[英]How to initialize custom analogue for std::cout?

我正在嘗試實現自己的basic_string ,但在打印字符串時遇到了問題。 我不會使用std::char_traits和 std 的其他特征,因為我自己已經實現了。 如何創建可用於我的字符串的std::cout的直接模擬並為此使用std::basic_ostream ? (不會自己創建basi ...

為什么 std::basic_string 有兩個獨立的模板參數 _Elem (char type) 和 _Traits (char traits)?

[英]Why does std::basic_string have two separate template parameters _Elem (char type) and _Traits (char traits)?

問題是我不明白為什么這些應該分開。 為什么不使用一個 class,如 CharType,它包含 char 特征和 char 類型的邏輯。 我的意思是替換它: 接着就,隨即: 其中 ExtendedTraits 是 _Elem 和 _Traits 的預置組合,可能看起來像這樣: 我嘗試實施這兩種方法 ...

boost屬性樹的自定義數據類型(繼承字符串)

[英]Custom data type for boost property tree (inheriting string)

我知道這個字符串業務是個壞主意,但無論如何我都必須知道它: 所以我想使用屬性樹讀取 xml ,同時將它存儲在我自己的數據類型中:字符串的子項。 這是我嘗試過的,但沒有運氣: 如果你有提升,代碼是可運行的。 這些是編譯時拋出的錯誤: #1- /opt/homebrew/include/boost/ ...

如何將 std::string_view 與反向迭代器一起使用?

[英]How to use std::string_view with reverse iterators?

我正在嘗試創建一個非常簡單的 function: 為了避免不必要的分配,我想我可以使用 string_view: 然而,最后一個 function 編譯失敗,因為編譯器找不到合適的構造函數(我嘗試了 g++ 12.2 和 clang++ 15.0)。 為什么在這種情況下沒有構造函數 while s ...

我不明白 std::string 來自 std::stream

[英]I do not understand std::string from std::stream

盡管我害怕顯得很愚蠢,但我想問一下為什么這個程序:#include <iostream> #include <fstream> int main(int argc, char * argv[]) { std::ifstream fitData("./fitData. ...

std::cin>> 是數字或字符串

[英]std::cin>> is digit or string

我必須確定輸入是數字還是字符串。 為此我收到error: no matching function for call to 'isdigit(std::__cxx11::string&)'有人可以提出我應該使用的方法嗎? ...

如果我肯定會復制它,如何有效地將字符串傳遞給 function? C++20

[英]How to efficiently pass a string to a function if I will certainly copy it? C++20

我想知道如何正確處理 function 中的字符串輸入,如果我知道我必須在其中制作一個副本以將其放入容器中。 我正在考慮這樣做: 但是,如果我傳遞一個 char* 字符串,我將制作 2 個副本,首先是在調用 foo 時,然后在將其傳遞給容器時。 我的第二個想法是使用 string_view,正如人 ...

在 char* 指針中復制 std::string 的一部分

[英]Copy a part of an std::string in a char* pointer

假設我在 C++ 中有這個代碼片段 我需要復制str中的字符串data (第一個和最后一個字符除外)。 我似乎可行的解決方案是創建一個 substring 然后像這樣執行std::copy操作 但也許這有點矯枉過正,因為我創建了一個新字符串。 有沒有更簡單的方法來實現這個目標? 也許在std:cop ...

VS2022:std::string.c_str() 懸空指針警告

[英]VS2022: std::string.c_str() Dangling pointer warning

我從 VS2022 收到此代碼片段的懸空指針警告: 警告 getProgramUUID()返回一個std::string並定義為 基本上,這只是c_str()返回的指針的memcpy 。 知道這是一個真正的問題,還是這只是 VS 迂腐? 問候, 阿布舍克 ...


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