-
June 11th, 2013, 10:17 AM
#16
Re: Visual studio C++ 2008 MFC quiz app
As questions.dat was being opened in create mode, its original contents have probably been deleted. You will probably have to re-create the file's content. It may be useful to mark the file as read-only once you are happy with the contents to prevent the contents from being accidentially deleted again.
And what is the contents of 'crap.txt'. Have you looked at the content outside of your program to verify it is correct? Seek does not make a file empty. It mearly adjusts the file pointer position within an opened file.
Last edited by 2kaud; June 11th, 2013 at 10:21 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 11th, 2013, 10:20 AM
#17
Re: Visual studio C++ 2008 MFC quiz app
sorry, i forgot to add:
keep in mind that "myFile.Seek( 0, CFile::begin );" made the whole file empty
-
June 11th, 2013, 10:21 AM
#18
Re: Visual studio C++ 2008 MFC quiz app
Originally Posted by Joe412
sorry, i forgot to add:
keep in mind that "myFile.Seek( 0, CFile::begin );" made the whole file empty
No it didn't. Opening it with CFile::modeCreate emptied it.
-
June 11th, 2013, 10:24 AM
#19
Re: Visual studio C++ 2008 MFC quiz app
GCDEF
check the new version of the code, there is no CFille::modeCreate in it
2kaud
i made crap.txt just to test out the validity of the program, later on i will change it into questions.dat
-
June 11th, 2013, 10:28 AM
#20
Re: Visual studio C++ 2008 MFC quiz app
But outside of your program, what are the contents of 'crap.txt' now? Seek does not empty it! If the contents are what you expect, make the file read-only as I suggested in post #16 then your program won't be able to empty it!
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 11th, 2013, 10:52 AM
#21
Re: Visual studio C++ 2008 MFC quiz app
http://www.fileconvoy.com/dfl.php?id...7731cc62118975
can anyone see whats wrong with this? Im really trying to learn MFC and generally want to learn programming so badly
im 16 and i wish i would like to be one when i finish high-school
-
June 11th, 2013, 11:22 AM
#22
Re: Visual studio C++ 2008 MFC quiz app
I've looked at your question text file. IMO you would be better off using the c++ STL file fstream class and the string class as this would allow you to read each line of the text file without knowing the number of chars in each line. Using CFile and Read you need to know how many bytes to read.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 11th, 2013, 11:24 AM
#23
Re: Visual studio C++ 2008 MFC quiz app
Originally Posted by 2kaud
I've looked at your question text file. IMO you would be better off using the c++ STL file fstream class and the string class as this would allow you to read each line of the text file without knowing the number of chars in each line. Using CFile and Read you need to know how many bytes to read.
could you do something with it? i need something that works and my hands are tied
-
June 11th, 2013, 11:39 AM
#24
Re: Visual studio C++ 2008 MFC quiz app
Originally Posted by Joe412
could you do something with it? i need something that works and my hands are tied
Why? Is this a class assignment?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 11th, 2013, 12:12 PM
#25
Re: Visual studio C++ 2008 MFC quiz app
Originally Posted by 2kaud
I've looked at your question text file. IMO you would be better off using the c++ STL file fstream class and the string class as this would allow you to read each line of the text file without knowing the number of chars in each line. Using CFile and Read you need to know how many bytes to read.
CStdioFile and ReadString would work too and fit his goal of trying to learn MFC.
Last edited by GCDEF; June 11th, 2013 at 12:17 PM.
-
June 11th, 2013, 12:16 PM
#26
Re: Visual studio C++ 2008 MFC quiz app
Originally Posted by Joe412
crap.txt is empty and you're trying to read it.
-
June 11th, 2013, 12:22 PM
#27
Re: Visual studio C++ 2008 MFC quiz app
Originally Posted by 2kaud
Why? Is this a class assignment?
Yes, and this is like a final task that would judge what grade am i going to get at the end, but i dont know how to do this because i was given the hardest one
-
June 11th, 2013, 01:57 PM
#28
Re: Visual studio C++ 2008 MFC quiz app
OK, right. I've downloaded your program, re-compiled it and run it. The solution creates quiz.exe in the folder quiz/debug. In this folder you have the text file questions.txt - but not crap.txt! On my system if you copy questions.txt to crap.txt in the folder quiz/debug and then run the quiz.exe program in quiz/debug as it stands, you get what you would expect. So if you now change your program to use questions.txt then it should be OK - as the program quiz.exe is in the folder quiz/debug which is also the folder where questions.txt resides.
The file you open needs to be in the same folder as the exe program you create/run - otherwise it needs to be given a path as well as a name. That's why you seem to have the problem as crap.txt is in the folder quiz/quiz!
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 11th, 2013, 03:09 PM
#29
Re: Visual studio C++ 2008 MFC quiz app
Originally Posted by 2kaud
OK, right. I've downloaded your program, re-compiled it and run it. The solution creates quiz.exe in the folder quiz/debug. In this folder you have the text file questions.txt - but not crap.txt! On my system if you copy questions.txt to crap.txt in the folder quiz/debug and then run the quiz.exe program in quiz/debug as it stands, you get what you would expect. So if you now change your program to use questions.txt then it should be OK - as the program quiz.exe is in the folder quiz/debug which is also the folder where questions.txt resides.
The file you open needs to be in the same folder as the exe program you create/run - otherwise it needs to be given a path as well as a name. That's why you seem to have the problem as crap.txt is in the folder quiz/quiz!
like i said before i made crap.txt just to test out if the file imput works, i used crap.txt because i've used a different algorithm that i copied
the task was to take input from the file, copy a question to a groupbox, and then pick an asnwer A,B,C,D displayed on the left(radio). After i've picked an answer i press next and if i got the question correct i get 1 point
this of course sounds ridiculously simple, but i've had had trouble with getting input from the file to the program and it has made me miserable and sleepless(being this is day 3). Also just to let people know i know command line c++ much much much^3 better than Microsoft's MFC visual c++
this task is due to tomorow afternoon and im sure every respected programmer on this forum and i dont know how to repay them if they did this
also where can i get some c++ general training
-
June 11th, 2013, 04:23 PM
#30
Re: Visual studio C++ 2008 MFC quiz app
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|