CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2012

    Really stumped, data input from txt

    Hi guys. I have this code.
    #include <string>
    #include <iostream>
    #include <fstream>
    #include <math.h>
    #include <sstream>
    string scoresort[9];
    int HighScore(int PlayerScore){
    int x;   
      				  fstream scorefile ("scores.txt");
    				  string line;
    				  if (scorefile.is_open())
    				    while (scorefile.good() )
    					getline (scorefile,line);
            			scoresort[x] = line.c_str();
    				    cout << line << endl;
    				  else {cout << "File NOT opening";}
    for(int i;i < 10; i++){ 				
    cout << scoresort[0].substr (3,0) << endl;	  	  	  	  
    //  std::ostringstream o;
    //  o << playerscore;
    Now I can't put data into the array scoresort[x]. I have tried everything. When the scoresort[x] is not an array I can input data. Although when it is an array it crashes my program. It will not process the line.

    This is part of the HighScore section for a game that I am currently making. Any help would greatly be appreciated.

  2. #2
    Join Date
    Jan 2006

    Re: Really stumped, data input from txt

    You did not initialise x.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.