I have jsut started to learn C++, and I am working on my 5th program. It is a fairly simple "labyrinth" style game. Minus the maze (for now), because I lack graphic abilties. I used an array to mark the dimensions of the room. and with every step, I force the player to solve a problem.
I wrote the program below to write the "list" function for me. All that is left is to add the questions and answers. I need a program/code that will read the line of code I want from "file_A", which has a list from all my Q&A, and write that line in "file_B".
I know how to read from a file. But not how to copy specific lines of text. Do you know where I can find to code that will allow me to do that?
If you can just point me towards a guide/tutorial that can show me how to write a program to do what I need. Or show me a code that I can look at and learn from. That would be awesome.
The way I wrote my game is: The functions that handles the questions returns 3 values.
1- The type of question it is.
2- The question the player needs to solve.
3- The answer to the question.
The guides I have been using only teach the basics of reading and writing to a file. What I use in the program above is as far as it goes. I can write to a file, append to a file, copy over a file, or print the texts of a file. I have no more control than that, atm. I have looked but I havent found anything that does the simple job that I need.
Thank you for your help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
int x;
int y;
ofstream a_file ( "list.cpp", ios::app );
a_file<<"void list() \n{\n\nstring word2;\n\n";
for ( x = 0; x < 4;x++ ) {
for ( y = 0; y < 4; y++ )
a_file<< " if ((x == " << x << ") && (y ==" << y << "))\n {"
<< "\n string word2 = question(,,,); \n }\n\n";
}
a_file.close();
}
|