2010-12-07 30 views
0

単語の最後の文字を文字列に変更したい。C++文字列[4]を文字列に変換する

ありがとうございました!

EDIT:

string x = "apple"; char c = apple[4]; string q = ""; 
string z = q+c; 
+3

うん...何ですか?これまでに得たことを示すコードを投稿して、達成したいことの例を教えてください。 –

+1

あなたは何を求めているのか分かりません。 – pisfire

+0

のような単語は、C文字列ですか?文字列クラスがオーバーロードされています=演算子。 –

答えて

0

この作品ができます。それは彼の機能要件が何であるかにいくつかの洞察を提供してJonの未遂答えを追加しますか?あなたが文字を持っている場合

string x = "apple"; 
char c = apple[4]; 
string q = ""; 

string z = q+c; 
+0

コードを選択してから、101 010ボタンをクリックしてください。 –

+1

これは 'string x =" apple ";文字列z(1、x [4]); ' –

1
std::string x = "apple"; 
std::string z(x.substr(4, 1)); 
0

は[] = "Laleluこれはために、言葉を選んだ単語:P" []編曲:CHAR言うことができます。

次にあなたが試みることができる:

std::string str; str.assign(&arr[strlen(arr)-5], 4); 
0

これを試してみてください。..

std::string apple = "apple"; 
std::string fpp(apple.rbegin(), apple.rbegin() + 1); 
0

このような何か試してみてください:私はへのアクセス権を持っていないとして、テストされていない

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。

+0

' char'だけを使用するコンストラクタはありません。サイズも 'string(1、LastChar); 'のように指定する必要があります。 – Nim

+0

@Nim Thanks、Edited 。 – Maxpm

関連する問題