Thread: getline() function

  1. #1

    Post getline() function

    I was reading a C++ tutorial and the person writing it said to get a full line of text without stopping at the first space use getline(), I use visual c++ and it doesn't work. Is it a real function?

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Yes, post some code.
    zen

  3. #3

    Post getline()

    #include <iostream.h>
    #include <string.h>
    #include <iomanip.h>

    using namespace std;


    int main()
    {
    char name[40];

    cout << "Enter your name: " << endl;
    getline(cin,name);
    cout << "Your name is: " << setw(3) << name;
    return 0;
    }

    and anytime I try to use "namespace std" MSVC++ says std is not a type of namespace.

  4. #4
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    When using getline to read into a character array, it's an istream member function -

    Code:
    #include <iostream> 
    #include <iomanip> 
    
    using namespace std; 
    
    
    int main() 
    { 
    char name[40]; 
    
    cout << "Enter your name: " << endl; 
    cin.getline(name,40); 
    cout << "Your name is: " << setw(3) << name; 
    return 0; 
    }
    zen

  5. #5

    Talking getline()

    Hey, Thanks it works!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. getline function for ansi c
    By crash88 in forum C Programming
    Replies: 3
    Last Post: 05-07-2006, 05:29 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. getline function to read 1 line from a text file
    By kes103 in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2004, 06:21 PM