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

    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;
    NAME5006
    NAME3050
    NAME3213

    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.

    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;
    				      
    					  x++;
    				    }
    				    
    				  }
    				
    				  else {cout << "File NOT opening";}
    for(int i;i < 10; i++){ 				
    cout << scoresort[0].substr (3,0) << endl;	  	  	  	  
    }
    				
    				
    				scorefile.close();
       
    //  std::ostringstream o;
    //  o << playerscore;
      	      
      
       
      return(PlayerScore);
    }

  2. #2
    Join Date
    Jan 2003
    Location
    Wallisellen (Zürich), Switzerland
    Posts
    16,178

    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

+ Reply to Thread

Bookmarks

Posting Permissions

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



HTML5 Development Center

Click Here to Expand Forum to Full Width