Thread: getline with string class in Borland C++

  1. #1
    Registered User johnnyd's Avatar
    Join Date
    Mar 2002
    Posts
    70

    Unhappy getline with string class in Borland C++

    I'm having a problem. I'm trying to use getline to capture a data in a string object from the user. The problem is that getline doesn't seem to be recognized by Borland C++ for string data capture.

    It is defined for char * handling, but I see don't see where it supports the string class data type.

    Here is a sample snippet:

    Code:
    #include <iostream.h>
    #include <string>
    
    void main()
    {
       string sName;
       char cName[50];
    
       cin.getline(cName, 50, '\n'); // this works
    
       getline(cin, sName); // this doesn't
    }
    When I try to use the second getline call, the compiler gives me the following error:

    Call to undefined function 'getline'


    I am using Borland C++ 5.02 - which has a lotta stuff defined radically differently than how I see it everywhere else - especially in this forum. For example, it is iostream.h that contains the getline function, not string.h.

    Also, apparently cin and cout are not members of the std class. But that's just the tip of the iceberg.

    Also, the following variations don't work either:

    Code:
    cin.getline(sName, 50, '\n');
    getline(std::cin, sName); 
    //as suggested by Prelude in a previous response to another post
    I gladly welcome your insights into this rather peculiar issue. Thanks.
    Excuse me, while I water my money tree.

  2. #2
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    This works in Code Warrior

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main(void)
    {
      string temp;
    	
      getline(cin, temp);
    	
      cout << temp;
    	
      return 0;
    }
    try the using namepsace std;
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  3. #3
    Registered User johnnyd's Avatar
    Join Date
    Mar 2002
    Posts
    70

    Lightbulb string stringName(char *)

    Hey, thanks for the reply.

    Unfortunately, that doesn't work either. This time I get the error:

    Error: Could not find a match for 'std::getline(istream_withassign,std::basic_string <char,std::string_char_traits<char>,std::allocator <char>>)'
    So what I did was this:

    Code:
    char someString[50];
    
    getline(someString, 50, '\n');
    
    string realString(someString);
    Basically what that does is initialize the string type that I want with the character array that I got from the user.

    Thanks for your help anyway. I guess Borland C++ just sucks like that.
    Excuse me, while I water my money tree.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    you could try upgrading to borland bcc55. that might help some.

  5. #5
    Registered User johnnyd's Avatar
    Join Date
    Mar 2002
    Posts
    70

    Where do I get that?

    Where do I get the latest version without purchasing new software? I already own BCB 5.02. Do you know if it can be upgraded for free?
    Excuse me, while I water my money tree.

  6. #6
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Better not add a direct link as I'm not sure what the mods would do.

    http://www.borland.com/products/down...cbuilder.html#

    Get the commandline tools and try that one, or you could try dev c

  7. #7
    Registered User johnnyd's Avatar
    Join Date
    Mar 2002
    Posts
    70

    Talking I got a better Idea

    I totally forgot there was a place where I could go and get the latest version. Thanks for your suggestions.
    Excuse me, while I water my money tree.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  2. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 03:40 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. class object manipulation
    By guda in forum C++ Programming
    Replies: 2
    Last Post: 10-09-2004, 10:43 AM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM