1

I need to input a line of characters, discard invalid characters, but keep the valid ones. Getline and get aren't working. It prints my cout "invalid" statements before user can input. I'm trying to input character array now. How to break out of loop once user has hit "return"?

while(cin)
{
   cin>>chararray[length];
   length++;
}

1 Answer 1

1
while(true)
{
   cin>>chararray[length];
   if (cin.get() == '\n')
        break;
   length++;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.