我想将单词的最后一个字符更改为字符串。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