0
I need my code to be able to store the word in the string s for it to be reversed, but there's something wrong. Please help?
#include <iostream> #include <string> using namespace std; int main() { string s; int i = 0; int j = s.size() - 1; char temp; cout << "Enter a word." << endl; cin >> s ; while (j>i) {; temp = s[j]; s[j] = s[i]; s[i] = temp; ++i; --j; } cout << s; }
3 odpowiedzi
+ 5
What would you do if someone asked you for the length of a string before you knew the actual string?
Pretty much what is happening here.
+ 1
std::reverse(s) might help as well
0
Saw the problem and solved it!