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

Hybrid View

  1. #1
    Join Date
    Nov 2012

    Need help! C++, data from txt file into an array.

    When I try an put the input data into an array it crashes my program. I can put it into a single string but not an array of strings... This is needed so I can bring all the data in to compare it and rearrange it.
    Data format in file;

    These are highScores for a game I am currently making. I want to rearrange them so they can be output in order on the highscore page.

    Any help appreciated.

    #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;

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: Need help! C++, data from txt file into an array.

    You have already got an answer in your other thread.
    Why do you create the second thread with the exactly the same question?
    Victor Nijegorodov

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.