-
Getline help!
Code:
#include <iostream>
using namespace std;
int main()
{
string user_input;
string computer_output;
int x;
int b;
int cin;
cout<<"Hey people I am a program"<<endl;
cout<<"named Blubster! You can talk to me like a normal person"<<endl;
cout<<"and I will reply!"<<endl;
while ( x != 1 ){
getline (cin, user_input, '/n');
cout<<user_input;
if ( user_input == "end" );
{
x = 1;
}
cout<<"Goodbye!";
cin.get();
}
This doesnt want to work pls help!
-
what doesn't work? the website? You can't post? your bike?
-
try '\n' instead of '/n'
Kurt
-
-
You still didn't say what doesn't work. Post compiler errors or the incorrect behavior. You have a semi-colon after the if that shouldn't be there. You didn't add the closing brace for the while loop. You shouldn't name a variable cin, and you don't need that variable anyway.
-
it says no matching function call for getline line 28. missing } after input line 29. get has not been declared line 28
EDIT it doesnt compile at all
-
You're passing getline's arguments in the wrong order.
Code:
#include <string>
istream& getline( istream& is, string& s, char delimiter = '\n' );
Follow the prototype by passing them in the right order.
-
so how am I supposed to fix it?
-
One way is to do it right, this time.
-
1. don't declare int cin; cin is used for input
2. your missing a brace
-
>> it says no matching function call for getline line 28. missing } after input line 29. get has not been declared line 28.
That helps. You need to #include <string> because you are using the string class and the string version of getline.
>> You're passing getline's arguments in the wrong order. Follow the prototype by passing them in the right order.
The arguments were already in the correct order in the original post.