Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Creating basic prompt and adding user input to string array

$
0
0
So I'm pretty new to C/C++ but have experience with a lot of Java. Basically I'm trying to make a prompt in the terminal that will take the user input and add it to a string array. I'm writing the program in C++ but will eventually have to use the c_str() function to generate a c-style array of chars.

Anyway, before all that, I'm having a problem with one little thing. The prompt for user input is going to be issued until "exit" is typed. If nothing is typed and just enter is pressed I want it to go to the new line and issue "prompt:" again but I'm not sure on the right way to do that. This way does not work and seems to enter some sort of infinite loop.

	
string input;

cout << "[ prompt: ] ";

    while (input != "exit")
    {
        getline(cin, input);
    
        if (input == "\n")
        {
            cout << "[ prompt: ] ";
        }
    }


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>