fstream.get() not breaking at end line

I'm trying to read a file line by line, it's been a long time since I did any programming in c++, and I'm porting a simple app from javascript to c++ to get my barrings back.

Input file:
#HOME
:-240, 64, 262
:-399, 198, 64
#CAVE
:-343, -203, 81
:-452, -465, 61
#rubber tree
:-414, -539, 64
#canyon
:-294, 233, 64
#sheeeeeeeep
:-382, -62, 68
:-529, 399, 65
:-522, -164, 64


Source code in question:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int main(int argc, char** argv) {
  std::ifstream* f = new std::ifstream();
  f->open("./coordinates");
  if(! f->is_open() ) {
    std::cout << "Failed to open coordinates.\n";
    delete f;
    return -1;
  };
  std::stack<waypoint::Location*>* locations = new std::stack<waypoint::Location*>();
  char* line = new char[24];
  waypoint::Parser* p = new  waypoint::Parser();
  while(! f->eof() ) {
    f->get(line, 24, '\r'); 
    std::cout << line << std::endl;
    // do stuff with line locations and parse
  }
  f->close();
  delete f;
  delete locations;
  delete p;
  delete[] line;
  return 0;
}


output of line 14:
#HOME
:-240, 64, 262
:-
399, 198, 64
#CAVE
:-34
3, -203, 81
:-452, -465
, 61
#rubber tree
:-414
, -539, 64
#canyon
:-29
4, 233, 64
#sheeeeeeeep

:-382, -62, 68
:-529,
399, 65
:-522, -164, 64



Any idea what I'm doing wrong? I can't remember if there's a more idiomatic way of doing it in C++
Last edited on
http://www.cplusplus.com/reference/string/string/getline/

that will read a line in. See the examples on that page.

Thanks!

Ugh, rookie mistakes all over again. Haha, it's gunna take a little bit before I'm back up to speed.
It's not working for the same reason this isn't working.
http://www.cplusplus.com/forum/beginner/127222/#msg688443

As a rule, try not to think of an fstream as a file, but think of it as a stream. That means:
1. Don't call open/close on it
2. Don't check for EOF
3. Don't seek around the file (unless you really have to)
Topic archived. No new replies allowed.