You have a string of digits from 1-8.Now you need to increase each digit by 1 and put back in the same index of the string. But you canβt use additional containers. How can you do it?
Input: 12345678
Output:23456789
My typecasting process seems not to working .
string s;cin>>s;
int n=s.size();
for(int i=0;i<n;++i){
s[i]=(char)(s[i]-'0'+1);
}
cout<<s;
@ssjgz bro (char)(s[i]-β0β+1); this part is not giving any value why?
s=β234β;
for i=0
value will be (char)(2-48+1) which is negative but it should print something ?
sorry for mistake but if U try to print only this (char)(50-48+1) which is char(3) (in a loop to get all value increment but not adding 0 ) so i am not getting out see->
int main()
{
string s="234";
for(int i=0; i<s.length(); i++)
{
s[i]=(char)(s[i]-'0'+1);
//cout<<s[i];
}
cout<<s<<nl;
}
output for this is nothing.
You should see the ASCII table first then you will get the idea.
EOT is similar to NewLine char(10).
When you send some data like a text then, when the receiving device sees EOT it will stop receiving data or it will see NEWLINE it will do accordingly. Similarly, there are some other char you can see in the ASCII table.
It has nothing to do with the string.
When you start cout it will start collecting data and will print. But you introduced EOT at the start means there is nothing to print.
Also, EOT will take 3 spaces, So if you print a length 5 string starting with EOT, it should print the last 2 characters of the string.