C/C++ :: Fstream Load Data Function?
Mar 21, 2015
Ive used a similar approach to extract data from a txt file before, however now it seems to crash when i get to the load, below is the code with a NOTE next to where it crashes. This is homework so no code but just information on why it was working for one dataset but not his new one.
/*
The purpose of this program is to read in data and sort with selection and insertion sort. It will read data from file and write to a new file the sorted data
*/
#include <iostream>
#include <fstream>
using namespace std;
bool openFile(ifstream&);
[code].....
View 2 Replies
ADVERTISEMENT
Jun 5, 2014
I have been trying to figure this out for a text based game. Lets say your money is 500. Then you save your game, but when you start the game the starting is 50, so when you load it, you still have 500 money, I tried lots of test, and im having trouble?
View 10 Replies
View Related
Apr 14, 2013
I'm working on a program which creates data and saves it into blocks (different files), then reloads and converts it all. the .ftl file saves properly, but for some unknown reason, it won't let me open it for input after.
Here's the significant code:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
stringstream filename;
stringstream newfilename;
string Filename;
[Code] ....
setblock will typically = 3, but for testing purposes is set to 1. this really has me confused. the compiler i'm using is Dev-C++ 5.2.0.1 on xp. i have tried pausing the program after the output file is closed, confirming the file has been created in the proper directory before continuing but still fails the .is_open() check.
View 4 Replies
View Related
Jul 9, 2014
fstream ifs;
ifs.open ("data.str", ios::binary | ios:ut);
char *data1 = "data1";
char *data2 = "data2";
ifs.write(data1, strlen(data1));
ifs.write(data2, strlen(data2));
when i this,data2 is not going under data1, i thought each write starts on a new line?
View 4 Replies
View Related
Apr 20, 2014
I am trying to make a log in system which load data from a .dat .... So I have a part of code below
if(radioButton1->Checked)//Login {
String ^ userAC = textBox1->Text;
String ^ userPW = textBox2->Text;
char ACc[300];
char PWc[300];
[Code] ....
I built it and it is a success but when i run it, it have error: Debug Assertion Failed!
Program:....
File:....Microsoft Visual Studio 10.0VCincludexstring
Line: 930
Expression: invalid null pointer
.......
What is going wrong so i try to comment some part to debug. I found that it come form the code
string AC(ACc);
string PW(PWc);
String ^ ACstr;
String ^ PWstr;
MarshalString(ACstr,AC);
MarshalString(PWstr,PW);
I tried to use std::string and System::string when getting data from .dat but it failed so i tried char array.
View 2 Replies
View Related
Sep 11, 2013
What data_type will read in a string of letters mixed with numbers using fstream :);
View 1 Replies
View Related
Dec 4, 2014
Basically for homework, we gotta make an array of payroll objects, using the general format I've made below...
I'm having trouble. The .dat file we are given to test looks like this:
40.0 10.00
38.5 9.50
16.0 7.50
42.5 8.25
22.5 9.50
40.0 8.00
38.0 8.00
40.0 9.00
44.0 11.75
When I execute the program, it shows the first column of objects, but will always replace the 2nd column values with a 0.
It's definitely NOT reading that column, and using the constructor to set it to zero. I don't know why it's not reading that column though...
(TL;DR.... Currently it reads "Employee #1: 40, 0" rather than "Employee #1: 40, 10.00"... etc)
Here's my code.... (not 100% done yet just testing datafile output atm)
#include <iostream>
#include <fstream>
using namespace std;
class Payroll {
private:
double payRate; // holds an employee hourly pay rate
[code]....
I want it to read the other column without giving me zero />
View 2 Replies
View Related
Jul 6, 2013
I want my function to take 'fstream' object as an input, so the program looks like this:
Code:
#include <fstream>
using namespace std;
void test(fstream a){
a.open("test2.txt");
a << "123" << endl
[Code] ....
But I get error: 'std::ios_base::ios_base(const std::ios_base&)' is private|
View 3 Replies
View Related
Oct 22, 2013
My load function isnt working. I've tested it and returned it as an int and it worked but when i tried to compile when i changed it to a template i started getting the errors and I'm not sure how to fix it:
all_sort.cpp:41:15: error: no matching function for call to 'load'
int *value = load("./integers.txt", size);
^~~~
./bubble_sort.h:44:4: note: candidate template ignored: couldn't infer template
argument 'T'
T *load(const char* x, int &size) {
[Code] ....
I'm trying to use my load function to load integers from a file into and array and then return it back.
#include "bubble_sort.h"
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main(){
int n, pick = 1, size = 0;
[Code] ....
View 1 Replies
View Related
Feb 18, 2014
For some unknown reason when i try the following code it doesn't create a file. (the program will simply get two inputs from the user and then use http to obtain the html/php text and then output it to a file)
code:
#include <SFML/Network.hpp>
#include <iostream>
using std::cout;
[Code].....
View 3 Replies
View Related
Apr 4, 2014
I want to design a class that will open a text file and manipulate the data in it. And I have to use all these functions from fstream like ifstream, ofstream, seekg etc. The problem is that I can't get the first part to work (getting my constructor to open the file using ifstream). I've posted my test.h file below.
#ifndef TEST_H_INCLUDED
#define TEST_H_INCLUDED
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
using std::ifstream;
class Test {
[Code] ....
View 2 Replies
View Related
Feb 14, 2014
So, I am making a name-database-type-thing and I want the user to be able to enter there own file. Like, here:
string fileName;
string name;
cout<<"What is your file name?"<<endl;
getline(cin, fileName);
ifstream nameFile(fileName);
getline(cin, name);
nameFile<<"Name: "<<endl;
Well, that last part is in a loop, so you can enter an unlimited number of names to the .txt file.
So, it won't let me use the string in ifstream. How can I fix this? This maybe unclear, so if it is just say so and I will edit it.
View 6 Replies
View Related
Feb 2, 2013
I'm trying to input a html file and copy everything from that file to a new html file with some changes. I need to read the html file word by word and compare them to a file with some keywords. If a keyword matches a word in the html file then it will add italic tags around that word in the output html file. As it is now it doesn't output anything.
Logically I want to read a word from the html file and then compare it to every keyword and output the result.
fileIn = original html file
keyword = keywords file
outFile = html file writing to
std::string str;
std:: string word;
[Code]...
View 2 Replies
View Related
Oct 16, 2013
I have a file of data where each line consists of 4 parameters (degree, alpha, beta and x) and a value corresponding to these, organized in increasing order of the parameters. Here's the test file I'm using:
0 1 1 0.5 3.5
1 1 1 -0.5 -0.5
1 2 0 0.2 4.5
1 3 0 0.2 -4.5
2 0 0 1.5 2.1
2 1 0 0 5.6
My code is supposed to look for a certain set of parameters (currently set to 1 2 1 1.5, which is not contained in the file) and its value. If it's there (i.e. the file contains the value for the right parameters) the program is done. If not it should calculate the value using a function JacobiPoly() and insert the wanted parameters and corresponding value in the appropriate place in the file.
I have a code in which I think everything works except the writing to file. I use an fstream so I can both read and write and open it with ios::out||ios::in. I'm also aware I need something similar to fseek in between input and output but according to [URL] .... reading and writing to the same file using the same fstream, seekp() should suffice. I'm using seekp(), but the output (in the form inout << (...)) doesn't work.
Here's the code:
fstream inout;
inout.open("inouttest.dat", ios::out | ios::in);
int degree=1, readDeg;
double alpha=2, beta=1, x=1.5, value, readAlpha, readBeta, readX, readVal;
bool foundVal=false;
streampos beforeRead=(streampos)0;
[Code] ....
View 3 Replies
View Related
Sep 7, 2012
I want to edit the contents of a file using fstream, but none of the modes in the fstream constructor work for me.
If I use ios::trunc, then the whole file is deleted - but I want to retain the contents and edit it. If I use ios::app, then I can only add data to the end of the file - but I want to edit the data in the middle of the file. If I use ios::ate, then the whole file is deleted again, similar to ios::trunc.
How can I create an fstream object without deleting the contents of the file, whilst still being able to move the pointer arbitrarily around in the file with seekp() (and not just placing it at the end as with ios::app)?
View 3 Replies
View Related
Nov 9, 2012
I did some of the projects using STL container and it is pretty much efficient to retrieve the data's information quickly (i.e. sets, sets & maps). I read many C++ OOP book and none of them make me clear about the Link Between (STL) Container and (Fstream) File I/O. Can they link together ?
I am going to design a small Library Book Management Project. I am planning to develop it using the STL Algorithms & containers. Objective of this project is to keeping the records of books issued and deposited by students in a particular date. User will be given a facility to retrieve student's information, book information and he/she can modify/update specific book's, student's information by changing issue date, deposited date, Book's publication etc.
My intention is to create a File I/O where user can input & update/modify daily transaction inside the file called (xx.dat) file in project directory. Is it possible to create 'set' container inside the file (xx.dat) ? Or, It's impossible ? Or, do i have to do this in other way?
View 6 Replies
View Related
Jul 25, 2013
How to forbid file replacing in fstream library for C++?
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream myfile;
[Code] ....
View 5 Replies
View Related
Dec 16, 2014
I'm trying to make a simple phonebook app that can show contacts, add, and delete. I'm pretty new to C++ and fstream functions, deleting a line in my bool erase() function?
#include <iostream>
#include <conio.h>
#include <string>
[Code].....
View 6 Replies
View Related
Jan 20, 2013
other posts talk about the fopen function and don't really give any solutions to this the var that has the file path is a char* and has been converted from a system::string^ it is completely valid when I paste it in windows bar.
Code:
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
if(textBox1->Text[0] == (char)'' || textBox2->Text[0] == (char)''){
MessageBox::Show("Please select a valid m3u and path", "Problem",
MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
[Code]....
it crashes right at the pile.open() function call when I put breakpoints in it says , debug assertion failed and shows me the fclose.c file location and Expression: (stream != NULL)
View 5 Replies
View Related
Feb 7, 2014
I've been having this odd problem when I write a file byte by byte, when I write a byte (dec)10 it adds a (dec)13 in front of it, and as far as I can tell, this is the only byte value that does this.
and most annoyingly, I can't read that (dec)13 with fstream, the only reason I know it's adds it, is because I used an external hex editor.
here is the code that causes the problem:
Code:
#include <fstream>
using namespace std;
int main()
{
[Code]...
but the output file reads '0D 0A' (that's in hex, '13 10' in decimal) when viewed in a hex editor. no other number (that I've tried) adds that extra 13.
View 2 Replies
View Related
Jun 10, 2013
If the filename below is a directory, then the following loop goes to infinite.
std::ifstream in;
in.open(filename, std::ifstream::in);
if(in.fail()) return;
[Code].....
View 1 Replies
View Related
Jan 1, 2014
Im about to program a RPG and, of course, the player has got an inventory. The items in this inventory are stored in a linked list and have IDs in form of strings.
player.cpp: (just the most relevant)
#include <list>
#include <string>
using namespace std;
[Code] ....
Of course, when the player saves the game, the inventory has to be saved too.
game.cpp(just the m. R.)
#include <fstream>
using namespace std;
class CGame{
[Code] .....
Now, in my code I write the linked list into the file savegames.sav
void CGame::save(CPlayer* player){
m_out.open("savegames.sav", ios::out);
m_out.write((char* ) &player->m_inventory, sizeof(player->m_inventory));
m_out.close();
}
In another function i load the list:
void CGame::load(CPlayer* player){
m_in.open("savegames.sav", ios::in);
m_in.read((char* ) player->m_inventory, sizeof(player->m_inventory));
m_in.read();
}
And when i access the loaded linked list with the .empty() function or so, Windows says the following:
<Mygame.exe> funktioniert nicht mehr (in English: doesnt run anymore).
I tried so much to fix that but i dint reach my aim.
View 2 Replies
View Related
Jan 15, 2014
I need to a simple example for writing class' objects to a text file using fstream , I tried to search the forums and I found binary examples but not for to a text file.
View 8 Replies
View Related
Nov 20, 2012
I'm using Visual C++ 6.0 and I'm trying to use fstream to open and read a file that is created only during runtime. This file is written by another function running on another thread, and my program will keep trying to "open" the file until it can be opened, i.e. after it's created, then read 3 numbers from it and execute the rest of its code.
The file test.txt has the content
Code:
1
3
4
My program that polls and opens the file is as follows:
Code:
ifstream fin;
std::string tfile, snum1, snum2, snum3;
long int num2, num3;
tfile.assign(argv[1]);
printf("Begin prog %s
", tfile.c_str());
[code]....
I executed the program by
Code: test_prog.exe "C: est.txt"
and waited about 3 seconds before putting the test.txt file into C:
My output was
Code:
Begin prog C: est.txt
Cannot open file C: est.txt
Cannot open file C: est.txt
Cannot open file C: est.txt
Cannot open file C: est.txt
Cannot open file C: est.txt
Cannot open file C: est.txt
fin is open
snum1 =
num2 = 0 num3 = 0
End of prog
The test.txt file disappears after I refresh the C: folder.
So the values for snum1, num2 and num3 are all wrong, as if the file was not read correctly.
If I put a while fin.good() loop after printf("fin is open "); for that entire block (until printing the values of num2 and num3), then I get
Code:
Begin prog C: est.txt
Cannot open file C: est.txt
Cannot open file C: est.txt
Cannot open file C: est.txt
Cannot open file C: est.txt
Cannot open file C: est.txt
Cannot open file C: est.txt
fin is open
End of prog
How can I correctly read a file that is only created during runtime?
View 4 Replies
View Related
Sep 26, 2013
Let's say I create a small program or just want to open any kind of file on my computer, but I want to run a program that forces the user to enter a password or something (I already know this part). How does one create the code that would open the file?
View 5 Replies
View Related
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