getline() don't want to work anymore...

This is a discussion on getline() don't want to work anymore... within the C++ Programming forums, part of the General Programming Boards category; Hi, I've got some problem with getline(), it doesn't want to work and I get some puzzling errors from the ...

  1. #1
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114

    Unhappy getline() don't want to work anymore...

    Hi, I've got some problem with getline(), it doesn't want to work and I get some puzzling errors from the compiler... So I want to read on a file using "getline", a string and the file itself... So I have something like this, and it always worked before:

    Code:
    std::ifstream File;
    std::string Temp;
    
    File.open("somefile.ext", std::ios::in);
    std::getline(File, Temp); //doesn't work...
    getline(File, Temp); //doesn't work either...
    I don't understand why, but I get errors telling me that "getline" couldn't be found, or that "std::getline" isn't part of "std::"... I have included in my file those headers:

    Code:
    #include "iostream"
    #include "string.h"
    #include "fstream"
    And even if I try with/without "using namespace std;" it doesn't change a thing...
    However in all my previous program I used getline this way and it always worked, but in this case I don't have a clue... Even if you point your cursor on "getline()" and see what are its prototypes, it seems to be of "std"... It writes some "std::basic_istream" things so I believe it should be working...

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    The string class, and it's getline function reside in <string>, not <string.h>.
    My best code is written with the delete key.

  3. #3
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114

    Thumbs up

    Wha? It was just that! So simple! Now it works correctly! Thanks a lot!

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    ... em, shouldn't the followint (

    #include "iostream"
    #include "string.h"
    #include "fstream"

    ) be the following?

    #include <iostream>
    #include <string.h>
    #include <fstream>

    ??

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Quote Originally Posted by twomers
    ... em, shouldn't the followint (

    #include "iostream"
    #include "string.h"
    #include "fstream"

    ) be the following?

    #include <iostream>
    #include <string.h>
    #include <fstream>

    ??
    To match common practice, yes. It's harmless though. If the implementation-defined locations that the compiler searches for "..." don't contain the standard headers, the search is attempted again using <...>. At worst, it's a time sink.
    My best code is written with the delete key.

  6. #6
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    I didn't know that there was a differnce between the "" and the <>... So standard headers should use these <> if they are located in our compiler's headers directory? But on the other hand, using <> on other-directories includes shouldn't fail.?

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I didn't know that there was a differnce between the "" and the <>...
    Technically there isn't. Both search implementation defined locations that are unspecified. But it's accepted practice that standard headers go in <...> and everything else goes in "...".
    My best code is written with the delete key.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,849
    I tend to use <> for anything (even 3rd party libraries) which have been configured in the IDE / makefile as additional include search paths.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 11:39 PM
  2. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  3. Why won't my OpenGL work?
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 11-26-2005, 11:53 AM
  4. Help with getline() and file reading
    By evilkillerfiggi in forum C++ Programming
    Replies: 5
    Last Post: 10-15-2005, 04:49 PM
  5. Developers Wanted
    By Quasicom in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 08-24-2005, 01:46 AM

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