In the below code
#include<iostream>
#include<string>
using namespace std;
int main()
{
string a,c="!";
cin>>a;
int l=a.size();
for(int i=0;i<l;i++)
{
c=c+"#"+a[i];
}
cout<<c;
}
If I replace c=c+"#"+a[i] with c+="#"+a[i] i get unexpected output. Output in the second case is !boxboxboxbox irrespective of input on https://www.onlinegdb.com/ . On "dev c++" the output is -
But a += b is equivalent to a = a + b . Then what is the reason for the difference in output?
Aucun commentaire:
Enregistrer un commentaire