470,643 Members | 1,537 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,643 developers. It's quick & easy.

Why does this code only run like 15 letters?

#include <iostream>
#include <string>

using namespace std;


int main()
{

string setning;
string temp;

getline(cin,setning);

for (int i = 0 ; i < setning.size(); i++ ){
temp[0+i] = setning[setning.size()-1-i];
cout<<temp[i]<<' ';
}


return 0;
}

I figured it out
Nov 26 '20 #1
2 3529
dev7060
570 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. temp[0+i] = setning[setning.size()-1-i];
0 has no significance here.
Nov 26 '20 #2
AjayGohil
83 64KB
Hi,

Your code is perfectly working for any number of letter and it reverse string.
you can try below method for reverse string:

https://www.geeksforgeeks.org/getline-string-c/
Dec 16 '20 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Roshawn Dawson | last post: by
10 posts views Thread by simon.hibbs | last post: by
54 posts views Thread by smnoff | last post: by
31 posts views Thread by somenath | last post: by
7 posts views Thread by Artie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.