FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Reading Map file - C++





flatliner
I currently have a map file in a txt format. such as the below code

Code:
1:0 0:0 0:0 1:0


I need a way to separate them out without using fscanf().
For example the way my map format works is the space is the delimiting character and then the first number on the left hand side of the colon is the TileID and then the number the other side is TileType.

I have tried to use getline() but it doesn't allow the same functionalty as fscanf(); Such as the code below

Code:
fscanf(FileHandle, "%d:%d ", &tempTile.TileID, &tempTile.TypeID);
AftershockVibe
Getline() should work fine if you set the delimiter and use it twice.

First use " " (space), then you can split using ":".

Why can't you use fscanf() ?
flatliner
AftershockVibe wrote:
Getline() should work fine if you set the delimiter and use it twice.

First use " " (space), then you can split using ":".

Why can't you use fscanf() ?


Yea I tired that alright, but I couldn't seem to assign the value to the member variables of the class I made. I will just double check it again and then post the code I tired.

Erm well I using ifstream which as far as I know cannot be used with fscanf() also I have hear fscanf() is evil Twisted Evil Laughing well so I heard anyway. I am not really sure, I am a novice at C++ atm.

Thanks for your reply Very Happy
flatliner
Yea I still get an error

Code:
getline(myfile,TempContainer,' ');
   getline(TempContainer,Temp ,':');


Quote:
error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided


I will keep tinkering with it and see how I get on. I dont know why its throwing this error. It should take 3 arguments.
flatliner
ok I got it sourced using scanf_s() instead. Check out the below code

Code:
while (! myfile.eof())
      {
         
         CTile tempTile;


            while ( getline(myfile, TempContainer, ' ' ) )
            {   
               
               sscanf_s(TempContainer.c_str(), "%d:%d ", &tempTile.TileID, &tempTile.TypeID);         
         
               CError::Report("pushback");
               TileList.push_back(tempTile);
            }
         

      }
Related topics
Tutorials
Tutorials-How To Install Winxp And Linux To The Same Compute
Problem with Yahoo Messenger
Customise your Windows XP for free.
uploading system
science vs. religion
PHP Test File
403 Error On My Smf Forums Index.php
Upload a preset file using PHP
Help with Restricting certain websites from being viewed
hulp nodig, snel!!
HELP, reading text file from USB drive in visual basic
US soldier suicides over torture, Iraq
Very slow DVD burning process
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.