C++ Converting string[4] to a string
I want to chang开发者_如何学运维e the last character of a word to be a string.
thanks!
EDIT: adding Jon's attempted answer as it provides some insight into what his functional requirement is:
string x = "apple"; char c = apple[4]; string q = "";
string z = q+c;
std::string x = "apple";
std::string z(x.substr(4, 1));
If you got a char[] lets say char arr[] = "Lalelu THis is a for-worded word:P";
Then you could try:
std::string str; str.assign(&arr[strlen(arr)-5], 4);
try this..
std::string apple = "apple";
std::string fpp(apple.rbegin(), apple.rbegin() + 1);
Try something like this:
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.
Untested, as I don't have access to a compiler ATM.
Could this work?
string x = "apple";
char c = apple[4];
string q = "";
string z = q+c;
精彩评论