#include "ellison.h"
int main(int argc, char *argv[])
{
if (argc > 1)
{
int errorOutput = Execute(argc, argv);
switch (errorOutput)
{
case 0:
return EXIT_SUCCESS;
break;
default:
cout << "An error occured: " << ParseError(errorOutput);
return ERROR;
break;
}
}
cout << "+---------------+ \n";
cout << "| ellison 0.1.1 | \n";
cout << "+---------------+ \n\n";
int errorOutput = 0;
string input;
while (true)
{
cout << ">";
input = "";
cin >> input;
if (input == "quit")
{
if (errorOutput != 0)
return ERROR;
else
return EXIT_SUCCESS;
}
errorOutput = Execute(input);
switch (errorOutput)
{
case 0:
break;
default:
cout << "An error occured: " << ParseError(errorOutput);
break;
}
}
}
This code compiles and runs fine. The strange part is, that if I type in a long string of letters with one or more spaces, I have two greater than signs, instead of one. Is there some kind of an error that I made?
I will add that this doesn’t work with short input strings, and that this was compiled with Visual-C++ 2012
std::cin only reads until the first space. Then, it doesn’t flush the read buffer.
So, because of your “while(true)”, when it gets to the second std::cin, it reads the second part of your input without waiting for a new input.
You should try std::getline(stream& readingBuffer, std::string& destination) instead. It will read the whole line, like such:
Just don’t use cin and getline at the same time unless you use cin.ignore(1) after using cin, because cin leaves a ‘/n’ in the stream. If you use getline right after on the same stream, it will stop at that ‘/n’, not reading what you wanted to read.