Thread: Getline help!

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    South Africa
    Posts
    11

    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!

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    what doesn't work? the website? You can't post? your bike?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    try '\n' instead of '/n'
    Kurt

  4. #4
    Registered User
    Join Date
    Mar 2006
    Location
    South Africa
    Posts
    11
    still doesnt work

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    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.

  6. #6
    Registered User
    Join Date
    Mar 2006
    Location
    South Africa
    Posts
    11
    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
    Last edited by really_bad_prog; 06-23-2006 at 03:11 PM. Reason: add on

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    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.
    Last edited by whiteflags; 06-23-2006 at 03:24 PM.

  8. #8
    Registered User
    Join Date
    Mar 2006
    Location
    South Africa
    Posts
    11
    so how am I supposed to fix it?

  9. #9
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    One way is to do it right, this time.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  10. #10
    Registered User
    Join Date
    Apr 2004
    Posts
    42
    1. don't declare int cin; cin is used for input
    2. your missing a brace

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> 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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  2. getline problem
    By Bitphire in forum C++ Programming
    Replies: 5
    Last Post: 10-18-2004, 04:42 PM
  3. getline help
    By ProjectsProject in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2004, 11:12 AM
  4. getline not working right
    By talz13 in forum C++ Programming
    Replies: 11
    Last Post: 12-10-2003, 11:46 PM
  5. getline with string class in Borland C++
    By johnnyd in forum C++ Programming
    Replies: 6
    Last Post: 03-08-2003, 02:59 PM