CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 35
  1. #16
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    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)

  2. #17
    Join Date
    Jun 2013
    Posts
    16

    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

  3. #18
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Visual studio C++ 2008 MFC quiz app

    Quote Originally Posted by Joe412 View Post
    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.

  4. #19
    Join Date
    Jun 2013
    Posts
    16

    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

  5. #20
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    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)

  6. #21
    Join Date
    Jun 2013
    Posts
    16

    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

  7. #22
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    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)

  8. #23
    Join Date
    Jun 2013
    Posts
    16

    Re: Visual studio C++ 2008 MFC quiz app

    Quote Originally Posted by 2kaud View Post
    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

  9. #24
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Visual studio C++ 2008 MFC quiz app

    Quote Originally Posted by Joe412 View Post
    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)

  10. #25
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Visual studio C++ 2008 MFC quiz app

    Quote Originally Posted by 2kaud View Post
    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.

  11. #26
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Visual studio C++ 2008 MFC quiz app

    Quote Originally Posted by Joe412 View Post
    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
    crap.txt is empty and you're trying to read it.

  12. #27
    Join Date
    Jun 2013
    Posts
    16

    Re: Visual studio C++ 2008 MFC quiz app

    Quote Originally Posted by 2kaud View Post
    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

  13. #28
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    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)

  14. #29
    Join Date
    Jun 2013
    Posts
    16

    Re: Visual studio C++ 2008 MFC quiz app

    Quote Originally Posted by 2kaud View Post
    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

  15. #30
    Join Date
    Jun 2013
    Posts
    16

    Re: Visual studio C++ 2008 MFC quiz app

    bumping

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured