On 2/15/12 3:50 PM, Byron Clark wrote:
> On 02/15/12 at 03:46pm, John Shaver wrote:
>> It kind of makes file processing strange if windows compilers treat
>> \r\n different than linux based compilers... They should both just
>> treat them as what they are. Otherwise, writing cross platform code
>> is more difficult.
>
One thing I've done in the past is to read in a line at a time with
getline and then parse each line character at a time instead of parsing
the whole file character by character. Then you don't have to add little
tweaks for '\r' that don't really have to do with your bus logic.
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[] ) {
ifstream infile("test.txt");
string line;
getline(infile,line);
for (; !infile.eof(); getline(infile,line) ) {
cout << "Got a line: " << line << endl;
// parse it however now...
}
return 0;
}
-Dennis
/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/