这是我在做leetcode 38题时遇到的坑,调试了好久才发现这个问题,如下。
#include <iostream>
#include <string>
using namespace std;
int main(){
string ans = "23";
string temp;
//(right)
//temp = temp + to_string(1) + ans[1];
//(right)
//temp = temp + "1" + ans[1];
//(right)
//temp += to_string(1) + ans[1];
//(error !!!)
temp += "1" + ans[1];
cout << temp << endl;
return 0;
}