Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-11-2007, 05:01 PM   #1
LQ Newbie
Registered: Jan 2007
Posts: 1

Rep: Reputation: 0
How can read from file.txt C++ where can save this file(file.txt) to start reading

everybody I am a beginner with C++ programming. And I need some help.

How can I start with this program

The program is using a text file of information as
the source of the questions. The program starts by outputting a simple text information
Question Master
This program tests your knowledge in your chosen category.
Use the load command to load up your set of questions. Type
help if you wish to see the available commands.
The program then enters a loop asking the user to:
Enter a command:
and processes the following set of commands:
end the program
LOAD <filename>
e.g. load capitals.txt
The program then opens that files, reads in the information and stores it in arrays
of string, and displays the text from the first line of the file which will describe
the category of questions and numbers of entries read in, e.g.
Category of questions: countries and their capitals
Number of entries: 193
If the file cannot be loaded then output an error message; so, if I tried to load a
file called wibble.txt and it didn't exist then the program would respond with:
"*** ERROR: Unable to open file wibble.txt ***"
NOTE: remember to use the clear() function after you have read in a file to
EOF (end-of-file) see lab notes.
The program displays the category of questions e.g.
Enter a command: play
Category of questions: countries and their capitals
then enters a loop asking questions based on the information loaded. The question
asked is made up from line 2 of the file (see below) and the entry from the name
array chosen at random. If the correct answer is given, then output "Well done"
followed by the number of correct answers so far - for example:
What is the capital of Denmark?
Well done. Correct answers: 1
Continue (yes/no)? yes
If an incorrect answer is given then correct them as follows:
What is the capital of Federated States of Micronesia?
Wrong: Federated States of Micronesia is linked with: Palikir
Continue (yes/no)? yes
After each attempt, ask them if they wish to continue (yes/no). If they
answer "no", then output the total of correct and incorrect answers, for
What is the capital of Croatia?
Well done. Correct answers: 2
Continue (yes/no)? no
Correct answers: 2
Incorrect answers: 1
Enter a command:
List the names and attributes stored in the array to the console screen preceded by
the category, the question, and the number of entries.
Simple text output describing these command options.

Format of the question files
There are two example files:
They both have the following format:
Line 1: the category e.g. countries and their capitals
Line 2: the question, e.g. what is the capital of
Lines: name, e.g. Australia
attribute, e.g. Canberra
each on its own line, repeated.
So the first block of the capitals file looks like this:
countries and their capitals
what is the capital of
Andorra la Vella

Old 01-11-2007, 05:11 PM   #2
Senior Member
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Um, homework? Try your professor first.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
reading a txt file vidyashankara Linux - Software 2 06-22-2006 06:52 PM
Reading from a txt file into a two dimension array in C kponenation Programming 3 11-26-2005 07:04 PM
Read a line in a txt file with bash orgazmo Linux - Newbie 3 05-03-2005 04:16 AM
Reading a txt file in terminal over a network mdlister Programming 5 03-14-2005 07:47 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:08 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration