Really stumped, data input from txt
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Really stumped, data input from txt

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Posts
    2

    Really stumped, data input from txt

    Hi guys. I have this code.
    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);
    }
    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
    Location
    Singapore
    Posts
    6,276

    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

This is a CodeGuru survey question.


Featured


HTML5 Development Center