getline() function

This is a discussion on getline() function within the C++ Programming forums, part of the General Programming Boards category; I was reading a C++ tutorial and the person writing it said to get a full line of text without ...

  1. #1
    Perverted unanimous's Avatar
    Join Date
    Oct 2001
    Posts
    336

    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?
    Give me a bad reputation!!!

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

  3. #3
    Perverted unanimous's Avatar
    Join Date
    Oct 2001
    Posts
    336

    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.
    Give me a bad reputation!!!

  4. #4
    zen
    zen is offline
    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
    Perverted unanimous's Avatar
    Join Date
    Oct 2001
    Posts
    336

    Talking getline()

    Hey, Thanks it works!!!!!
    Give me a bad reputation!!!

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, 09: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21