C++ :: Create Save File For A Game That Is Not A Separate File?

Oct 10, 2014

How do you create a save file for a game, that is not a separate file? Specifically I am using code::blocks and sfml 2.1 to make a game and it saves to a text file at the moment. My problem is that it is very easy to modify the text file, and it is annoying to have to copy and paste several files if you want to use a copy of the game. I have a feeling that it may be to do with resource files, but I'm not exactly sure how to get these to work or whether you can modify them dynamically.

View 6 Replies


ADVERTISEMENT

C++ :: Correct Guesses Before Game Was Over - Save To A Text File

Feb 12, 2013

cout << "You've made 3 mistakes ! Game is now over !" << endl;
cout << "You had " << correctGuesses << " correct guesses before the game was over" << endl;
this info into a text file...

example of a guessing game code...

#include <iostream>
#include <time.h>
using namespace std;
int main() {

cout << "This is a very simple number guessing game. Each time you will be given a number of the range 0-10." << endl;
cout << "The objective of the game is to guess whether the next number is going to be higher or not. As simple as that." << endl;

[Code] ....

View 1 Replies View Related

C++ :: Create User Defined Class And Have Access In Separate Header File From Main

Mar 15, 2013

I am a beginner with C++, taking a class right now. The lab this week is to create a user defined class and have it accesses in a separate .h header file from the main.

I think I'm finding my way through it, but I'm getting a complie error that makes no sense to me:

1> Resistor.cpp
1>c:users omdocumentsschoolcomp 220week 2lablab 2.2lab 2.2
esistor.h(11): error C2146: syntax error : missing ';' before identifier 'resistor'
1>c:users omdocumentsschoolcomp 220week 2lablab 2.2lab 2.2

[Code] .....

Here is the first portion of the .h file:

#include <iostream>
#include <iomanip>
#include <Windows.h>
#include <math.h>
#include <string>

class CResistor{
double res1, res2, res3, percentage, Nominal, Tolerance;

[Code] ....

View 16 Replies View Related

C :: Create A File And Save Text In It In PDF Format

Feb 13, 2014

My objective is to create a file and save some text in it. But the twist is that file should be created in pdf format.

I have written following code:

Code:
#include<stdio.h>

Code:
int main() { FILE *fp;
char ch;
fp=fopen("file.pdf","w");
fprintf(fp, "%PDF-1.3"); //to initiate data storage in pdf file
printf(" Enter data to be stored in to the file:");
while((ch=getchar())!=EOF)
putc(ch,fp);
fclose(fp);
return 0;}

Now my file is created in pdf format, but when I open it by double click on it, it is not open and gives the message like: "Error in opening document. This file is damaged and could not be repaired."

View 1 Replies View Related

C# :: How To Create Event To Notify And Save / Write Information To File

Feb 24, 2014

I am writing a program that models the ups & downs of a particular stock. Everything is pretty much done, except that I need to create another event to notify that saves the following information to a file when the stock's threshold is reached: date & time, stock name, initial value & current value. I have something like this so far:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

[Code]...

I feel like i need something along the lines of

s.stockEvent += new Delegate( ???? ) in my myFile class so it know when the threshold is reached, to write the information of the current stock to the file.

View 14 Replies View Related

C++ :: Create A Program That Is Able To Save Database Of Items To File On Hard Drive

Mar 18, 2013

Write a program that is able to save a list of items such as books, CDs, or DVDs and the items that are saved must have attributes associated with them. For example a book has a title, author, publisher, and ISBN.I would like to create a program that is able to save the database of items to a file on the hard drive and also retrieve it from the hard drive.I have this for a start of how to set up a storing program.

#include <iostream>
#include <iomanip>
using namespace std;
int main () {
const int arraySize = 10;
int a[arraySize] = { 2, 6, 4, 10, 12, 89, 68, 45, 37 };
int i, hold;

[code]....

View 2 Replies View Related

Visual C++ :: Unable To Save File Using Cfiledialog Save As In MFC

Nov 5, 2013

I am trying to develop a GUI using MFC, but I am having trouble using CFiledialog to save a file. The problem is, the file is not getting saved to the folder when I use the CFiledialog. Below is the code I am using.

Code:

CString szFilter = "XNRep Files (*.xnrep)|*.xnrep||";
CString s = "xnrep";
CString t = "";
CFileDialog fileDlg(FALSE, s, t, NULL, szFilter);
if(fileDlg.DoModal() == IDOK)
{
std::ofstream file;

[Code]....

After the file dialog opens up, I enter the name of the file and select OK button. But the file does not show up in the directory I am saving to.

View 4 Replies View Related

C++ :: How To Save File Directory To Text File Using Ofstream

Jul 22, 2013

I'm having a little problem with std:fstream - in my program, the user selects the location of a file which I want to remember. So, I have something like this:

Code: std::string fileLocation;
//Code here creates an 'open file' dialog box which lets the user choose which file to open.
//The string 'fileLocation' now contains the path to the chosen file.
std::ofstream prefs("prefs.txt");
if (prefs.is_open())
{
prefs << fileLocation;
prefs.close();
}

This works fine if the file chosen is in the same directory as the program, however, if they try to choose a directory outside of where the program is kept, it saves the text file into that directory instead of the same one as the program. So, it looks like outputting a directory into an ofstream actually changes the location to which the file is saved.

Is there a way to save the file directory to a text file using ofstream and still have the text file save in the same directory as the program?

View 5 Replies View Related

C++ :: How To Save Struct To File And Then Read It Back From The File

Aug 5, 2013

How to save the struct to file and then read it back from the file ?

Code:
#include <conio.h>
#include <stdio.h>
struct student {
int person;
int egn;
float AvergeGrade;

[Code] ....

Have average grade: %f", person[i].FirstName, person[i].LastName, person[i].egn, person[i].AvergeGrade);
}
//Save to file
getch ();
}

View 2 Replies View Related

C/C++ :: How To Add Functions To Class In A Separate File

Jan 31, 2014

I could do the assignment if all i had to do was create a function within one file, call it in the main class, and that would be done with it. no, my teacher wants us to have our main program, a header and a separate class file and create functions in it in which we can then use in the main file.

This is the main file:

#include <iostream>
#include "call.h"
using namespace std;
int main() {
int length; //holds the length of the call in minutes
int hour; //holds the hour od the day(0-23 military time)

[Code] .....

View 7 Replies View Related

C++ :: Member Function Undefined In Separate File

Feb 25, 2015

I have three files.

//headerfile NumArrSpecs.h
#ifndef NUMARR_H
#define NUMARR_H

[Code].....

My problem is that the storeElems member function is causing an error saying it is undefined, however there are no errors any where else in the program being reported. I have made several programs involving classes now, all with this three file format and this is the first time that a member function in the main file is being reported as undefined, so I'm not sure what to do.

View 2 Replies View Related

C++ :: Read From A File And Store Information In Separate Variables?

Dec 8, 2014

So I have to read from a file, and store the information in separate variables. My problem is that for some of the information I need multiple words, and for others I don't, so I cant simply store 1 word into a variable and store the next in another in so on. To demonstrate what I mean let me give an example.

Dog Cat Blue Bird Snake White Horse

I am able to store "Dog","Cat","Blue","Bird"...etc in variables but I don't know how to make it so I can store "Dog" in one variable, "Cat" in a second variable. and "Blue Bird" in a third variable. "Snake" would be the 4th and "White Horse" would be the fifth. How can I read a file and manipulate the pointer to grab what I need?

View 2 Replies View Related

C++ :: Accessing A Vector That Was Created In A Separate Header File?

Oct 26, 2014

i have this vector:

#ifndef new_thing_Inventory_h
#define new_thing_Inventory_h
#include <vector>
#include <string>
using namespace std;
class Inventory {

[code]....

so i know i need to use .push_back or .pop_back, but the program im using dosn't even recognize that inventory is a created vector.

View 6 Replies View Related

C++ :: Separating Routines Into A Separate Implementation And Header File

Oct 18, 2013

I am trying to separate out particular sets of routines into a separate implentation and header file which can be compiled independently to the main program such that the program source consists of a file called customers.h, customers.cpp, and exercise_1_5.cpp

Each of the files should contain the following:

customers.h should contain the definition of the customer structure and the declaration of print_customers.

customers.cpp should contain the implementation (or definition) for print_customers.

exercise_1_5.cpp should contain an include of customers.h and the main program.

This is my original code from a single .cpp file

#include<iostream>
#include<string>
using namespace std;

[Code].....

The error messages I am getting from the compiler on the customers.cpp file:

C:UsersBenDocumentsCS264lab3customers.cpp:5:22: error: variable or field 'print_customers' declared void
C:UsersBenDocumentsCS264lab3customers.cpp:5:22: error: 'customer' was not declared in this scope
C:UsersBenDocumentsCS264lab3customers.cpp:5:32: error: 'head' was not declared in this scope

View 6 Replies View Related

C :: Save And Load Game

Nov 26, 2013

I am trying to put my Save and Load function in my game, this is what i have:

Code:
/* Save game */
void GuardarJuego() {
FILE *fsave;
char turno;
fsave=fopen("SAVE.txt", "w");
fputs(*****, fsave);

[Code] .....

My game code is this: [C] GameCode - Pastebin.com

View 8 Replies View Related

C :: Create Separate Array That Consists Of The Same Number

Mar 6, 2015

I working on a big program, and it involves character arrays. What I want my function to do is create a seperate array that consists of the same number of "*" as there are letters in the word from the text file. For example, if the word sarc was up, the function show make ****. This was my attempt at it. I managed to reach this far. I can only fit in one "*". This is part of jumble game program I'm trying to make, and its in C language.

insert Code: void partialWord(char current[]){
int n;
int i;
n = strlen(current);
for (i = 0; i < n; i++){
current[i] = strcpy(current,"*");
}
printf("%s
", current);
}

View 7 Replies View Related

C++ :: Video Game - How To Set Up Save System

May 20, 2013

I would like to create a video game. It would be text based. How could I set up a save system? Also, how would I load it?

View 3 Replies View Related

C :: Create File To Write Text And Read Back The File Content

Mar 15, 2013

The Objective Of This Program Is To Create A File To Write Text And Read Back The File Content. To Do That I Have Made Two Function writeFile() To Write And readFile() To Read.The readFile() function works just fine but writeFile() doesn't.

How writeFile() function Works? when writeFile() function Execute It Takes Characters User Type And When Hit Enter(ASC|| 10) It Ask "More?(Y/N)" That Means What User Want? Want To Go Next Line Or End Input?

If "Y" Than Inputs Are Taken From Next Line Else Input Ends.

But The Problem Is When Program Encounters ch==10 It Shows "More?(Y/N)" And Takes Input In cmd variable.If cmd=='Y' I Mean More From Next Line Than It Should Execute Scanf Again To Take ch I Mean User Input.But Its Not!!! Its Always Showing "More?(Y/N)" Again And Again Like A Loop.

Code:
#include <stdio.h>
void writeFile(void);
void readFile(void);
int main(){

[Code].....

View 5 Replies View Related

C++ :: Create File With Given Size And Then Randomly Access File To Populate It

Feb 17, 2015

I am interested in creating a file of a given size and then randomly accessing the file to populate it. Is there a way to quickly create, for instance, a 4 GByte file in C++, initially populated with garbage?

View 4 Replies View Related

C/C++ :: Pass Path In File Handling To Create Or Open A File?

Jul 14, 2012

I have a folder "pics" in g: drive. There I want to create some text.txt file. Thus, the final path is "g:pics ext.txt".

How can I do that?

View 3 Replies View Related

C++ :: Read Story From Input File / Separate Words And Output Lines On Which The Word Occurs

Feb 21, 2014

I have program that is supposed to read in a story from an input file and separate the words and output the lines on which the word occurs. It needs to read in another input file that has a list of words (1 per line) to ignore. i.e. skip them when running through the story. This is what I have so far, I've changed multiple things trying to get it running....

#include<iostream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<string>
#include"split.h"

[Code] .....

View 1 Replies View Related

C/C++ :: How To Deserialize Save Game Data (specifically Skyrim)

Jul 29, 2014

I'm working on my first own project which is to collect some info from a save game file and then parse it to a website. Skyrim uses a .ess file extension, which to my knowledge is a binary file. I know how to open a file for reading but how to extract the info I need from there. Do all games use a standardized serialization or can the format of this file be anything?

If reading the binary file turns out to be too difficult, would it be possible to hook the game and retrieve info that way? If so, where would you recommend to start learning that stuff?

View 1 Replies View Related

C++ :: How To Save Data To File

Sep 28, 2013

what are the codes that will save the data then it will appear in a file (.txt).

I typed the name "SpongeBob SquarePants"

SpongeBob SquarePants

View 5 Replies View Related

C++ :: Save Class Into A File?

Jan 12, 2013

I am creating a program using the inheritance. The superclass is person and subclass is employee,manager etc. I will prompt the user to choose which subclass he want to save the record to but i dont know how to write and display the record of different subclass to and from a txt file.

View 4 Replies View Related

C :: Fprintf Does Not Save String To File

Jan 3, 2014

Code:

struct sth {
char* str;
} pt;
}
[code]...

fprintf does not save string to file. How can I put structure into list?

View 9 Replies View Related

C++ :: How To Save Two Arrays Into One Text File

May 11, 2013

I have a 4*4 array and a 8*8 arays in my c++ program and i would like to save those arrays in one textfile. How do i do that.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved