Compiler Errors with Getline()

This is a discussion on Compiler Errors with Getline() within the C++ Programming forums, part of the General Programming Boards category; im getting the following error with this bit of code; getline(cin,Customers[Number_of_Customers].Addresstwo,'\n'); 201 d:\comput~1.cpp no matching function for call to `getline ...

  1. #1
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147

    Compiler Errors with Getline()

    im getting the following error with this bit of code;

    getline(cin,Customers[Number_of_Customers].Addresstwo,'\n');

    201 d:\comput~1.cpp
    no matching function for call to `getline (_IO_istream_withassign &, char[15], char)'

    i have mixed cin >> with Getline() and am planning on changing them all to Getline() but shouldnt it still compile as the syntax is still correct?

    thanks,

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,475
    Second argument must be a string. It's passing getline a char array.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >no matching function for call to `getline (_IO_istream_withassign &, char[15], char)'
    You're using the wrong getline, or the wrong type. To use getline with a C-style string, there's a member function of cin that does it:
    Code:
    cin.getline ( Customers[Number_of_Customers].Addresstwo, sizeof Customers[Number_of_Customers].Addresstwo );
    The getline you're using is defined as a non-member function in the <string> header to support the string class.
    My best code is written with the delete key.

  4. #4
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    Quote Originally Posted by Prelude
    >no matching function for call to `getline (_IO_istream_withassign &, char[15], char)'
    You're using the wrong getline, or the wrong type. To use getline with a C-style string, there's a member function of cin that does it:
    Code:
    cin.getline ( Customers[Number_of_Customers].Addresstwo, sizeof Customers[Number_of_Customers].Addresstwo );
    The getline you're using is defined as a non-member function in the <string> header to support the string class.
    thanks Prelude, ive implemented your solution into my program, "Functions not working" thread.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    I would just use the string class completely and use the string version of getline everywhere instead.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. ASM beginner gets 24 compiler errors on hello world...
    By Desolation in forum Tech Board
    Replies: 12
    Last Post: 06-16-2007, 10:21 PM
  3. getline help
    By ProjectsProject in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2004, 11:12 AM
  4. bloodshed compiler errors
    By nerore in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2004, 02:37 PM
  5. Compiler errors
    By BellosX in forum C Programming
    Replies: 2
    Last Post: 09-21-2001, 03:24 AM

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