title: File I/O using COCOS2D-X
body: <p>I'm trying to load up a Comma Separated file called <code>POSDATA.GAMEDATA</code>. I've looked up several places on the internet and it turns out I need to do some tweaking and / or a different class.</p>
  
  <p>I tried using <code>ifstream</code>. However, it cannot open the file. Xcode 4.3.2 cannot seem to find my <code>POSDATA.GAMEDATA</code> file. I also tried to make the file using <code>ofstream</code> but when I use <code>open()</code> in both cases, the file is not opened.</p>
  
  <p>My code is something like this:</p>
  
  <pre><code>using namespace std;
  void FileLoader::loadFile( string p_WhichFile ) {
     // Local Variables
     string thisLine;
  
     // Open POSDATA.GAMEDATA
     ifstream dataStream;
     dataStream.open( p_WhichFile.c_str( ) );
  
     // Check if file is opened
     if ( !dataStream ) {
        cerr &lt;&lt; "[ ERROR ] Cannot load file:" &lt;&lt; p_WhichFile.c_str( ) &lt;&lt; endl;
        exit( 1 );
     }
  
     // Get lines of strings
     while ( getline( dataStream, thisLine ) ) {
        fileContents.push_back( thisLine ); // fileContents is a vector&lt; string &gt; object
     }
  
     dataStream.close( );
     cout &lt;&lt; "[ NOTICE ] Finished reading file" &lt;&lt; p_WhichFile &lt;&lt; endl;
  }
  </code></pre>
  
  <p>I've seen <code>CCFileUtils</code> but I can't seem to get how to use it.</p>
  
  <p><strong>EDIT</strong>: I've tried supplying the absolute path ( <code>/Users/LanceGray/Documents/LanceDev/COCOS2DX/cocos2dx/TestGame/Data/POSDATA.GAMEDATA</code> ) and it worked. However, I cannot do this since the game is supposed to be used in iOS devices and Android, so the path is not always the same on each device. Any help will be grealy appreciated.</p>