c-str

    0熱度

    2回答

    我有這樣的代碼塊,寫成strstream。我將它轉換爲sstream如下。我不確定,但我認爲printStream->str()正在返回一個字符串對象,其中包含printStream所指向的流緩衝區中的內容的副本(臨時),然後您將調用c_str()並獲取const char *,然後投射該常量,然後將該指針返回到函數作用域之外。我認爲,因爲您從printStream->str()得到的臨時值,您將

    0熱度

    1回答

    我使用Qt Creator和驗證碼: string execpath = ""; execpath += (QCoreApplication::applicationDirPath()).toStdString(); WinExec("ffmpeg -f dshow -t 32 -i audio=\"virtual-audio-capturer\" -y "+(execpath.c_str()

    0熱度

    1回答

    我在爲MSVCC/Windows編寫的項目上工作,我必須移植到GCC/Linux。該項目有它自己的字符串類,它將數據存儲在Qt的QString中。另外,爲了轉換爲wchar_t *這裏原是該方法(適用於Windows): const wchar_t* String::c_str() const { if (length() > 0) { return (const

    2熱度

    2回答

    這是關於處理std::string的const副本的STL實現之間的區別的問題。我有這樣簡短的測試,它不通過c_str()回到2常量複印和打印地址: #include <stdio.h> #include <string> using namespace std; int main() { string a("Hello World!"); const string

    3熱度

    2回答

    我正在設計一個模擬shell程序,我不能完全模仿「cd」命令。我試過chdir(),但那不起作用,所以我繼續試圖改變環境變量「PWD =」 這是我的,我想這可能是接近的。 (請,請,糾正我,如果我錯了,或者是被chdir更密切()) else if (command == "cd") { string pathEnv = "PWD="; string new

    1熱度

    1回答

    我不知道是否有一種方法,以避免在這種情況下,使用臨時字符串: tempString = inputString.substr(commaLast,commaCurrent-1); yPos = strtod(tempString.c_str(), NULL); 沒有辦法使用SUBSTR命令,並沒有先存儲在臨時串子返回c_str (假設我不想修改原始字符串)。

    2熱度

    3回答

    讓我先感謝您花時間閱讀本文。 我想讀C++中的文件。目前我有一個方法允許用戶在瀏覽器中選擇一個文件,並將其作爲'std :: string'返回。然後我必須打開這個文件,但是我爲此使用的方法使用了const char *。所以我需要從一個轉換到另一個。 如果在Windows中使用字符串讀取文件時有一個簡單的方法,那麼讓我知道它會解決我的整個問題。 當我從字符串轉換爲const char *時,使用

    1熱度

    1回答

    我有一個問題,我無法自己修復。 string filenameRaw; filenameRaw= argv[1]; function(filenameRaw.c_str(),...); function(const char* rawDataFile,const char* targetfieldFile,const char* resultFile,const char* filenam

    2熱度

    4回答

    下面是代碼: string fname = "/home/jack/example.csv"; ifstream csvin(fname.c_str()); if (csvin.eof()) { do_something; } 我的問題是:在什麼情況下eof()返回true。我有以下選項: 文件不存在。 文件爲空。 文件不存在或爲空。 不幸的是documentation沒有幫助

    2熱度

    5回答

    用C++我想實現我的類的toString()函數: void ClassName::toString(string& returnString) { sprintf(returnString.c_str(), "Position: (%f, %f, %f)\n", position.x, position.y, position.y); } 不過,我不斷收到此錯誤:類型爲cons