467,165 Members | 988 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,165 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
  • viewed: 3365
Share:
2 Replies
Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. temp[0+i] = setning[setning.size()-1-i];
0 has no significance here.
Nov 26 '20 #2
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@gmail.com | 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.