Click here to Skip to main content
15,888,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Release crashes but debug works. Pin
Stefan_Lang12-Apr-11 6:35
Stefan_Lang12-Apr-11 6:35 
GeneralRe: Release crashes but debug works. Pin
Albert Holguin12-Apr-11 7:09
professionalAlbert Holguin12-Apr-11 7:09 
GeneralRe: Release crashes but debug works. Pin
Stefan_Lang12-Apr-11 21:23
Stefan_Lang12-Apr-11 21:23 
GeneralRe: Release crashes but debug works. Pin
Albert Holguin11-Apr-11 16:04
professionalAlbert Holguin11-Apr-11 16:04 
GeneralRe: Release crashes but debug works. Pin
Cyclone_S15-Apr-11 9:49
Cyclone_S15-Apr-11 9:49 
AnswerRe: Release crashes but debug works. Pin
Stefan_Lang11-Apr-11 22:23
Stefan_Lang11-Apr-11 22:23 
GeneralRe: Release crashes but debug works. Pin
Cyclone_S15-Apr-11 9:45
Cyclone_S15-Apr-11 9:45 
GeneralRe: Release crashes but debug works. Pin
Stefan_Lang26-Apr-11 0:28
Stefan_Lang26-Apr-11 0:28 
Wait, are you saying you're reading a standard ASCII text file? Confused | :confused: If so, why bother reading it as binary, byte by byte? Just open a normal file stream and use its standard operator >> to stream the numbers into your variables.

Try these functions to write and read your
void WriteScores(const std::vector<int>& scores) {
   int nscores = (int) scores.size();
   std::ofstream scorestream("Myscores.txt");
   scorestream << nscores;            // write number of entries
   for (int i=0; i < nscores; ++i)
      scorestream << ' ' << scores[i]; // write entries, using blank (' ') as separator
}
int ReadScores(std::vector<int>& scores) {
   int nscores = 0;
   std::ifstream scorestream("Myscores.txt");
   scorestream >> nscores;
   scores.resize(nscores);
   for (int i=0; i < nscores; ++i)
      scorestream >> scores[i];
   return nscores;
}

You may want to add in some extra code to check for premature end of file or failure to create/write or read the file. You might also want to check the state of the filestream after reading each number to make sure an actual integer was read (if there was no integer, the resulting value will be 0, but since 0 may be a valid value, you can check on the state of your stream variable instead)
QuestionCMFCMenuBar, cleartype? [Solved] Pin
bob1697211-Apr-11 6:00
bob1697211-Apr-11 6:00 
AnswerRe: CMFCMenuBar, cleartype? Pin
Hans Dietrich11-Apr-11 6:23
mentorHans Dietrich11-Apr-11 6:23 
GeneralRe: CMFCMenuBar, cleartype? Pin
bob1697211-Apr-11 7:22
bob1697211-Apr-11 7:22 
AnswerRe: CMFCMenuBar, cleartype? Pin
Hans Dietrich11-Apr-11 13:02
mentorHans Dietrich11-Apr-11 13:02 
GeneralRe: CMFCMenuBar, cleartype? Pin
bob1697211-Apr-11 10:25
bob1697211-Apr-11 10:25 
QuestionHow to implement WebSocket Client in C Pin
Parthi_Appu11-Apr-11 1:48
Parthi_Appu11-Apr-11 1:48 
AnswerRe: How to implement WebSocket Client in C PinPopular
«_Superman_»11-Apr-11 2:24
professional«_Superman_»11-Apr-11 2:24 
GeneralRe: How to implement WebSocket Client in C Pin
Parthi_Appu11-Apr-11 20:49
Parthi_Appu11-Apr-11 20:49 
GeneralRe: How to implement WebSocket Client in C Pin
markkuk11-Apr-11 23:26
markkuk11-Apr-11 23:26 
GeneralRe: How to implement WebSocket Client in C Pin
Parthi_Appu12-Apr-11 2:58
Parthi_Appu12-Apr-11 2:58 
AnswerRe: How to implement WebSocket Client in C Pin
Indivara12-May-11 19:03
professionalIndivara12-May-11 19:03 
GeneralRe: How to implement WebSocket Client in C Pin
Manu Dhundi12-Dec-11 8:55
Manu Dhundi12-Dec-11 8:55 
QuestionHow can I check if LPCTSTR is empty ? Pin
_Flaviu10-Apr-11 20:57
_Flaviu10-Apr-11 20:57 
AnswerRe: How can I check if LPCTSTR is empty ? Pin
Hans Dietrich10-Apr-11 21:10
mentorHans Dietrich10-Apr-11 21:10 
GeneralRe: How can I check if LPCTSTR is empty ? Pin
_Flaviu10-Apr-11 21:20
_Flaviu10-Apr-11 21:20 
AnswerRe: How can I check if LPCTSTR is empty ? Pin
Rajesh R Subramanian10-Apr-11 21:22
professionalRajesh R Subramanian10-Apr-11 21:22 
AnswerRe: How can I check if LPCTSTR is empty ? Pin
Rob Grainger10-Apr-11 23:44
Rob Grainger10-Apr-11 23:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.