https://leetcode.com/problems/reverse-string/
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".转换字符串。string跟char之间的赋值又忘了怎么弄了。。。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 #include2 #include 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 }
swap (string)
http://www.cplusplus.com/reference/string/string/swap-free/
C++中string的用法 string字符串的使用方法
http://jingyan.baidu.com/article/20b68a8854f919796dec6265.html标准C++中的string类的用法总结
http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.htmlc++中string的用法
http://www.cnblogs.com/yxnchinahlj/archive/2011/02/12/1952550.html浅析string 与char* char[]之间的转换
http://www.jb51.net/article/41917.htm