My last project of the year requires in part that I use stacks and queues to test data from the keyboard and/or a file and determine if the input is a palindromic string(chars are the same back and forth), a palindromic phrase(words read the same), or passage(sentences are the same back and forth.
I've got most of it working, but I can't figure the best way to read multiple lines in from the keyboard(to end the input, the user types in a '#' on a blank line, like:
1 2 3 4 5
|
hello bob
how are you
how are you
hello bob
#
|
This would not be a string or phrase, but would be a palindromic passage.
If I use cin, the input stops as soon as the user hits enter.
It's important that the input string still contains the '\n' characters so that I can properly split the lines and push them onto the stack.
I'm currently using what looks to me like ugliness, but it works well enough for me to at least finish other parts of the code and do some simple testing.
I'm using something like this:
1 2 3 4
|
string input;
char new_input[255];
cin.getline(new_input, 255, '#');
input=new_input;//cast char array to string
|
I tried to grab the cin.getline directly into the string, but I got an error "cannot convert char to string" or something like that, so I just used a character array and copied it into the string. This does what I need it to do, but what makes it totally unacceptable is the 255. I need to be able to input a string of any length.