我想將單詞的最後一個字符更改爲字符串。C++將字符串[4]轉換爲字符串
謝謝!
編輯:添加喬恩的嘗試回答,因爲它提供了一些洞察到他的功能要求是什麼:
string x = "apple"; char c = apple[4]; string q = "";
string z = q+c;
我想將單詞的最後一個字符更改爲字符串。C++將字符串[4]轉換爲字符串
謝謝!
編輯:添加喬恩的嘗試回答,因爲它提供了一些洞察到他的功能要求是什麼:
string x = "apple"; char c = apple[4]; string q = "";
string z = q+c;
莫非這項工作?
string x = "apple";
char c = apple[4];
string q = "";
string z = q+c;
std::string x = "apple";
std::string z(x.substr(4, 1));
如果你有一個char []可以說,焦炭ARR [] = 「Lalelu這是一個對措辭的話:P」;
那麼你可以嘗試:
std::string str; str.assign(&arr[strlen(arr)-5], 4);
試試這個..
std::string apple = "apple";
std::string fpp(apple.rbegin(), apple.rbegin() + 1);
嘗試是這樣的:
string MyString = "Whee!"; // String to extract letter from.
char LastChar = MyString.at(MyString.length() - 1); // Retrieves the last letter of the string and stores it as a char.
string LastCharAsString = string(1, LastChar); // Typecasts the char to a string.
未經檢驗的,因爲我沒有訪問編譯器ATM。
嗯......什麼?你可以發佈一些代碼來展示你到目前爲止的內容,並給我們一個你希望完成的例子嗎? – 2010-12-07 05:46:49
我不確定你在問什麼。 – pisfire 2010-12-07 05:47:00
單詞在c字符串?字符串類已重載=運算符。 – 2010-12-07 06:48:08