does this work on string in c++?
string s="lomi";
cout<<s<<endl;
what is bad in this code?
#include <iostream>
#include <cstring>
using namespace std;
int main(){
string s=string("lomi");
for (int i=0;i<s.length();i++){
s[i]= s[i]+3;
}
std::cout<<s<<std::endl;
return 0;
}
?
Yes.
(after you have
#included the corresponding headers, andusingthestdnamespace, etc.)Edit: What’s wrong with your code is you should
instead of
cstringis C’sstring.hheader, which defines functions likestrlen,strcpy, etc. that manipulates a C string, i.e.char*.stringdefines C++’sstringclass which you’re using.