I have been working on some question that involves converting ASCII value into string.
If I use this code, I get output as g, which is expected.
using namespace std;
int main()
{
int i=6; vector<string> ans;
string t= "";
t+=i+'a';
ans.push_back(t);
cout<<ans[0];
return 0;
}
However, If I change the code like this:
using namespace std;
int main()
{
int i=6; vector<string> ans;
string t= "";
t=t+i+'a'; // <----
ans.push_back(t);
cout<<ans[0];
return 0;
}
The following error is shown, when I try to compile it:
error: no match for 'operator+' (operand types are 'std::string' {aka 'std::__cxx11::basic_string<char>'} and 'int')
7 | t=t+i+'a';
| ~^~
| | |
| | int
| std::string {aka std::__cxx11::basic_string<char>}
The only difference between both the code is that in 1st code, I am using t+=i+'a';, while in second, t=t+i+'a'; is used.
Can someone please tell what is wrong with the second snippet?