-1

Can someone please give me a simple answer on how do I read a characters till the end of the line? I have tried typing

cin >> CHAR;

if (CHAR == '\n' || CHAR == '\0') cout << "?" << endl;

and none of this work for me, it just ignores this and reads further.

andrewc
  • 41
  • 2

1 Answers1

0

As a simple solution, you can do something along the lines of:

std::string s;
std::getline(std::cin, s));
for(const char& c : s){
    // Do something with the character
}

This will read a single line from std::cin and then loop through each character of the line.

Lilith Daemon
  • 1,473
  • 1
  • 19
  • 37