About Mikazo Tech Blog

My name is Mike, and this blog is my way of saving people time. If someone has a specific problem that I've encountered before, hopefully these posts will save them the extraneous Googling I had to go through to solve the same problem. Also, when I have something to say about technology today, I will post my thoughts here. If this blog has helped you out, even a little bit, vote on the poll below, or let me know by sending me an email. I'm always open to exchanging links with other blogs or websites that share a similar interest.

Saturday, November 29, 2008

C++ Reading Files Using ifstream and getline()

While doing a programming assignment in C++, I was trying to read data from a text file line by line using the following code snippet:

#include <fstream>
char line[2048];
ifstream in("data.txt");
in.getline(line,2048);


For some reason I was getting garbage being read from the file, but found out that the cause of the problem was the encoding of the text file. The text file I was using was Unicode. When I re-saved the file as ANSI encoding, the C++ program would then read the proper file data.

0 comments:

Donate to Mikazo Tech Blog