CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2014
    Posts
    3

    code stuck at getline...

    my code is not moving past the line below...actually i am making a quiz and this piece of code id checking whether the entered answer is correct, from a file.
    please tell me the possible reason for the problem..
    Code:
    getline(anss,saveans);
    Code:
    while(a<1)
    			{
    				getline(anss,saveans); 
    				if (saveans == ToString(randNum))
    				{
    					getline(anss,saveans);
    					if (saveans == ans)
    					{
    						cout<<"correct!"<<endl; 
    						cout<<"# next question # "<<endl;
    					}
    					else
    					{
    						cout<<"wrong answer!"<<endl; // Prints our STRING
    						cout<<"# next question # "<<endl;
    					}
    						break;
    				}
    			}

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: code stuck at getline...

    Point some breakpoints in your code and step through the code in a debugger. If you do this, the errors will become obvious.

  3. #3
    Join Date
    Apr 2014
    Posts
    3

    Re: code stuck at getline...

    I have tried it and found that it is not able to read the file that stores the answers...I cannot find the reason since the similar code is working in other part of my code that uses a different file...pls help

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: code stuck at getline...

    Rather than reading the file one question at a time, read the whole file and store each line in a collection.

  5. #5
    Join Date
    Apr 2014
    Posts
    3

    Re: code stuck at getline...

    i dont know how to do that?
    how is it done..?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

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