Advertisement

c++ strings

Started by July 01, 2000 03:49 PM
1 comment, last by dj9781 24 years, 6 months ago
Im having trouble with c++ strings. I want to have the user enter a string with spaces in it but I cant seem to get it to work right. Heres my code:
    
#include <iostream>
#include <string>

using namespace std;

void main()
{
    string s1;
    cout << "Enter string"<<endl;
    getline(cin,s1);
    cout << "You entered: " << s1;
}
    
It takes what the user enters but then you have to hit enter again. Is there anyway to fix this? I tried getline(cin,s1, '\n') but the same thing still happens. And does anyone know of any good tutorials on the net about c++ strings? Edited by - dj9781 on 7/1/00 4:30:08 PM
wow, a console app.
I havt done anything with it in a while but i think you use
getch()... Ill just say its an excercise to figure out how
exactly
Advertisement
Theres a bug in the getline function with some visual c++ compiler versions. There is a fix on the microsoft devnet website you may want to look at.....

This topic is closed to new replies.

Advertisement