Thread: Problem with getline()

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    Problem with getline()

    I'm new to programming so please be patient with me

    I'm trying to run a very simple code in Windows XP and in Code::Blocks with Borland Compiler (5.5, 5.82):

    Code:
    #include <iostream>
    
    using namespace std;
    
    string bla;
    
    int main()
    {
     getline(cin, bla);
    
     cout << "You entered: " << bla << endl;
    
    }
    as i press F9 to compile, the program crashes (it shows the usual "b.exe has encountered a problem and needs to close. We are sorry for the inconvenience." window)

    and in cmd it returns 0xC0000005 error

    If i use just "cin>>" everything works normaly...

    What is the problem and what can i do to manage it?

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    You forgot to include the string header.

    Code:
    #include <string>
    Edit: Warnings and errors mean things; but in this case was not the problem.

    Tested OK with 6.1 bcc.

    Edit: Tested with bcc 5.5.1 and it crashed.
    Edit: Tested with bcc 5.8.2 and it worked.
    Edit: Tested with bcc 5.9.2 and it worked.

    Looks like you need to upgrade to a newer version of bcc

    Tim S.
    Last edited by stahta01; 03-13-2011 at 07:33 PM.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Why are you using Borland? Old, poor compiler. Use GCC, that is my suggestion.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    2
    I switched to GCC and it worked, no more crashes... Tnx Elysia... i'll use GCC from now on then...

    @stahta01: I notice the errors and the warnings, but it didnt even come to that because it crashed before anything happened...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getline problem.
    By Swerve in forum C++ Programming
    Replies: 5
    Last Post: 10-05-2009, 01:17 PM
  2. Getting illegal case error
    By scmurphy64 in forum C Programming
    Replies: 2
    Last Post: 09-17-2009, 10:35 AM
  3. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  4. getline() problem
    By mrafcho001 in forum C++ Programming
    Replies: 5
    Last Post: 06-12-2005, 01:16 AM
  5. Need help with structures
    By yoursport in forum C++ Programming
    Replies: 8
    Last Post: 04-20-2005, 11:59 AM