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";
        }

    }

Recommended Answers

All 2 Replies

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

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";
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.