Computing.Net > Forums > Programming > Input file reading with C++

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Input file reading with C++

Reply to Message Icon

Name: igor12
Date: May 7, 2005 at 20:47:14 Pacific
OS: WInXp Pro
CPU/Ram: 2.4Ghz/1Gb
Comment:

I'm having trouble traversing an init file. It doesnt look like its even entering the while loop. Here is my function:

void intializeRoute( string filename, Route& route )
{
ifstream fin;
// fin.open( filename.data() );
fin.open (filename.data(), fstream::binary);

int i = 0;
string currentWord = "test";
cout << currentWord;
getchar();

while(fin >> currentWord)
{
if(currentWord.compare("!=") == 0)
if(currentWord.compare("=") == 0)
if(currentWord.compare("=!") == 0)
{
cout << "COMMENT" << endl;
string routeComment;
getline(fin, routeComment);
}
else if(currentWord.compare("TradingPost") == 0)
{
string name;
getline(fin, name);
name.erase(0, 1);
route.addTradingPost(name);
cout << "Trading Post Added" << endl;
getchar();
}
else if(currentWord.compare("Merchant") == 0) {
string merchName;
int currency;
fin >> merchName >> currency;
route.addMerchant(merchName, currency);
}
else if(currentWord.compare("Description") == 0) {
string desc;
getline( fin, desc );
desc.erase( 0, 1 );
route.addGoodDescription(desc);
}
else if(currentWord.compare("Good") == 0) {
string goodName;
int value;
fin >> value;
getline(fin, goodName);
goodName.erase(0, 1);
route.addGood(goodName, value);
}
else if(currentWord.compare("Arrangement") == 0) {
string tpDest, type;
int cost;
fin >> type >> cost;
getline(fin, tpDest);
tpDest.erase(0, 1);
route.addTravArrange(tpDest, type, cost);
}
else
cout << "Bad line in script" << endl;
i++;
}
fin.close();

cout << i;
getchar();
}

Those extraneous couts and getchars are for testing purposes.

Any ideas?
Igor



Sponsored Link
Ads by Google

Response Number 1
Name: gimmpy225
Date: May 8, 2005 at 19:51:01 Pacific
Reply:

I was just wondering if you live in the Texas DFW area, I have a friend at my school named Igor ( not trying to be mean in any way ) and it dosnt seem that popular of a name, I was wondeirng if you were him ^_^ cause that would be awesome if I knew someone who was into programming and comps like me :)

anywho ill look through your code and see what I can do, but I just figured id ask ya this anyways :)

understandable if you dont want to tell me anything.

GIMPS


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Input file reading with C++

File problems with c www.computing.net/answers/programming/file-problems-with-c/4685.html

prob with Linked list in C www.computing.net/answers/programming/prob-with-linked-list-in-c/481.html

i/o ras file with c program www.computing.net/answers/programming/io-ras-file-with-c-program/9579.html