Https://leetcode.com/problems/reverse-string/
Conversion string. I forgot how to assign values between string and char...
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 class Solution { 6 public: 7 string reverseString(string s) { 8 int i = 0, j = s.length() - 1; 9 char* sTemp = (char*)s.c_str();10 char temp;11 12 while (i < j)13 {14 // swap(s[i++], s[j--]);15 temp = sTemp[i];16 sTemp[i] = sTemp[j];17 sTemp[j] = temp;18 i++;19 j--;20 }21 22 return (string)sTemp;23 }24 };25 26 int main ()27 {28 Solution testSolution;29 string result = testSolution.reverseString("hello"); 30 31 cout << result << endl;32 33 char ch;34 cin >> ch;35 36 return 0;37 }
View code
Swap (string)
Http://www.cplusplus.com/reference/string/string/swap-free/
Use string in C ++
Http://jingyan.baidu.com/article/20b68a8854f919796dec6265.html
Summary of the usage of the string class in Standard C ++
Http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html
Usage of string in C ++
Http://www.cnblogs.com/yxnchinahlj/archive/2011/02/12/1952550.html
Analysis on conversion between string and char * char []
Http://www.jb51.net/article/41917.htm
Leetcode 344. Reverse string