|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
I am writing a "labyrinth" style game. Minus the maze, because lack of 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 that can read from "file_A", which has a list from all my Q&A, and write to "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? Thank you for your help. I cant wait to have this game finished. Code:
#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();
}
|
| Sponsored Links |
|
|
|
|||||
|
It will depend on the layout of the file.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. |
|
|||
|
Thats fine. I can set the file up any way I need to. 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 have my program set up 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 only that a noob like me can understand. I need to see a program to know how to use the code. Thank you for all your help. |
|
|||||
|
In that case, the getline (I think) function is probably going to be your key. Have each piece of info on its own line, and read the data in line by line.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Project: ionFiles - Joomla Simple File Download | Jordan | Community Projects | 331 | 11-26-2008 12:35 PM |
| File Manager | Jaan | Community Projects | 45 | 08-27-2008 12:11 PM |
| What mode should i use at fopen()? r, r+, w+b??? | tirengarfio | C and C++ | 3 | 08-14-2008 12:06 AM |
| Visual Studio 2008: C# Reading Files | Jordan | CSharp Tutorials | 8 | 06-20-2008 11:54 AM |
| Windows Shortcut List - Saves Time | 2stamlers | The Lounge | 6 | 04-10-2008 07:58 AM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |