0

I am getting an error on this code. Is it to do with whats in the while loop? How do i get it working?

Basically i want to be able to take in letter or number variables, and each would output something, and if they type exit it breaks out of the loop.

#include <string>

string input;

    while (input != 'exit')
    {
        cout << "OS#: ";
        getline (cin, input);

        if (input == 'a')
        {
            cout << "hello";
        }

    }

Edited by mystycs

2
Contributors
2
Replies
9
Views
3 Years
Discussion Span
Last Post by David W
0

Ahhhh it looks like i cant use '' i have to use quotations like "

Edited by mystycs

0

Yes ... you are correct ...

A string has: string s = "message";
A char has: char c = '!';

#include <string>

// ...

int main()
{
    std::string input = "" // nice to show, but not needed since "" IS default constructor value

    while( input != "exit" )
    {
        std::cout << "OS#: ";
        getline( std::cin, input );

        if( input == "a" )
        {
            std::cout << "hello";
        }
    }
}

Edited by David W: added content

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.