I am trying to learn basic C++ after being a Java developer. So I decided to give CLion a try. I wrote this basic code just to familiarize myself with some C++ syntax.
#include <iostream>
using namespace std;
int main() {
string word;
cout << "Enter a word to reverse characters: " << endl;
getline(cin, word);
for(int i = word.length(); i != -1; i--) {
cout << word[i];
}
return 0;
}
The code is functional. It reverses whatever word you input. I wanted to step through it to see variables and what not, and to test out CLion's debugger.
My problem occurs when I get to
getline(cin, word);
When I step onto this line, I enter a word and hit enter. Then step over. After I do this nothing happens; all the step over, in, etc. buttons are disabled. I am unable to continue through the loop, or run the remainder of the code.
I have used Eclipse's debugger many times for Java development without any issues. Any ideas could be helpful.
TL;DR How do I step through a C++ command line program with basic input and output using CLion?
string word; char wordReversedArray[word.length()];- you have an array with 0 length that you try to write into...cout << "str";write to the console/terminal. The console can buffer things up until it gets a newline. Trycout << "str" << endl;too see if that explains things...coutbefore your loop to display the word. Add acoutin your loop to displayi. See if eveything is as you expect. C++ uses 0 based indexes, soword[word.length]isn't valid.