std::getline size limit

This is a discussion on std::getline size limit within the C++ Programming forums, part of the General Programming Boards category; Hi everyone. I'm reading in each line off a file through std::getline(source,line,'\n'), but I've noticed that if the line is ...

  1. #1
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428

    std::getline size limit

    Hi everyone. I'm reading in each line off a file through std::getline(source,line,'\n'), but I've noticed that if the line is longer than 255 (or maybe it is 256...) characters, then the program will crash. "line" is an std::string so i don't think it has size restriction of 256. Is there a way to bypass this problem? Thanks.

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    Show some code please. Is source a std::string?

  3. #3
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    By the way, you can use:
    Code:
    std::getline(source, line)
    instead of:
    Code:
    std::getline(source,line,'\n')
    because the '\n is default.
    none...

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786

    Re: std::getline size limit

    Originally posted by dirkduck
    Hi everyone. I'm reading in each line off a file through std::getline(source,line,'\n'), but I've noticed that if the line is longer than 255 (or maybe it is 256...) characters, then the program will crash. "line" is an std::string so i don't think it has size restriction of 256. Is there a way to bypass this problem? Thanks.
    Hmm...doesnt crash for me.....can you follow the code throught the debugger to see exactly what point it crashes at?

    If it's a memory thing, try std::string::reserve with a count higher than the bytes read. See if that has an effect.

  5. #5
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Sounds like a potentially nonconforming compiler/STL implementation... what compiler?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Generic heapsort
    By Sephiroth1109 in forum C Programming
    Replies: 15
    Last Post: 12-07-2007, 05:14 PM
  3. Having a problem with templates and classes
    By bowluswj in forum C++ Programming
    Replies: 4
    Last Post: 06-26-2007, 12:55 PM
  4. An exercise in optimization
    By Prelude in forum Contests Board
    Replies: 10
    Last Post: 04-29-2005, 03:06 PM
  5. How can I extend the text size limit of TMemo from C++ Builder?
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 06-27-2002, 02:24 AM

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