35 Solved Topics

Remove Filter
Member Avatar for
Member Avatar for Nether_1

I'm writing a code that will save the username of a user when a button (in this case button1) gets pressed. I save it to a file called info.txt, and i use fstream in order to save it. Currently I'm running into the issue that, while i can open up …

Member Avatar for Nether_1
0
2K
Member Avatar for tgreiner

I am using fstream to open and close a file. The code works OK, except the the file does not close when I close it the first time. I need to invoke close twice. Any idea why? And, what this is saying about my code that I do not realize?? …

Member Avatar for Moschops
0
757
Member Avatar for markdean1989

I wonder why this program does not do any changes to the text file that I am trying to modify. Scenario: My program uses the Fstream header file, I declared infile as IFSTREAM and outfile as OFSTREAM. I simply want to transfer data from infile to outfile. The data is …

Member Avatar for markdean1989
0
354
Member Avatar for markdean1989

I wonder why this program does not do any changes to the text file that I am trying to modify. Scenario: My program uses the Fstream header file, I declared infile as IFSTREAM and outfile as OFSTREAM. I simply want to transfer data from infile to outfile. The data is …

Member Avatar for markdean1989
0
516
Member Avatar for jBat

I'm not understanding why i'm able to read from the file but i can't write to it. The fstream is open in both modes. Once the program finishes i haven't changed the content of the file. Thank you in advance. #include <fstream> #include <string> #include <iostream> int main() { std::string …

Member Avatar for jBat
0
778
Member Avatar for Labdabeta

Hello, I have a bug in my program somewhere and I cannot understand why. The program merely prints data from a binary file. Here is the code: #include <iostream> #include <fstream> #include <vector> #include <cstdint> using namespace std; int main(int argc, char *argv[]) { if (argc!=2) { cout<<"Invalid argument count, …

Member Avatar for Labdabeta
0
409
Member Avatar for Labdabeta

Hello, Looking at the standard streams provided by the stl libraries, it seems as though it is impossible to have 1 stream to use for both standard console IO and file/string IO. However, before I give up I would like to ask, is this possible: generic_stream stream; stream=cin; //now I …

Member Avatar for Labdabeta
1
512
Member Avatar for Elixir42

Dear Kind DaniWebbers, I am trying to overload the fstream operators (ofstream/ifstream), so that I can save a class to a 'Binary' file and also display it with cout. But the ways in which each need to be implemented is different. Please can you show me how to define different …

Member Avatar for vijayan121
0
4K
Member Avatar for H_beginner

I m reading data from a text file and then printing it. I am not sure what I am doing wrong but the program prints the last line that it reads twice. void bank_account::viewHistory() { ifstream in_file("bank_transaction_history.txt" , ios::in); if(!in_file) { cout<<"File error \n"; } cout<<"Event"<<setw(15)<<"Amount"<<setw(15)<<"Date"<<setw(20)<<"Current Balance"<<endl; string eve,dat; double …

Member Avatar for deceptikon
0
286
Member Avatar for furalise

Hi What is the difference between using the **fstream** library to read a file....and using something like a procedure below using the FILE* object? There seems to be two ways to read a file? Thanks /* FEOF example */ #include <stdio.h> int main() { FILE * pFile; char buffer [100]; …

Member Avatar for furalise
0
799
Member Avatar for gobiking

I have been getting used to c++ as I have been trying various scenarious on programs and exand on them with new concepts. This is my first try at exporting data from command line to a text file and the program runs fine with all the calculations. The real issue …

Member Avatar for gobiking
0
244
Member Avatar for josey_matt

Hi, could anybody please tell me what i am doing wrong in this program. The goal is to read the student name and grade from a text file and print it on the screen. This is what i have so far. by the way this is for a school project …

Member Avatar for siddiquedu
0
8K
Member Avatar for Jorox03

I am trying to add a comma to the end of each line ('\n') of a text file til the end of the file is reached. I am opening the file in append mode but am unsure as to how to go about identifying when the end of line is …

Member Avatar for Jorox03
0
3K
Member Avatar for Sci3nc3F1cti0n

I'm writing a program that will keep track of every Anime/Manga I watch/read(I'm an avid fan). I'm trying to make a database in order to keep track of all of the titles of the Anime/Manga. My problem is that when i try to add a new title to the existing …

Member Avatar for Sci3nc3F1cti0n
0
222
Member Avatar for 123386761

Hello! I'm new here, so correct me if this is the wrong location... but I'm trying to make a program for the Minecraft server I'm on, and it requires that if someone wants to make a map that is used on the server, that there's a .xml file that shows …

Member Avatar for 123386761
0
184
Member Avatar for marnun

Here is the exercise: > fileWord > Write the definition of a function named fileWord that receives a string argument that is the name of a file containing words. > > The first time the function is called, it returns the first word of the file whose name it was …

Member Avatar for marnun
0
259
Member Avatar for marnun

It seems I don't understand completely reading from and into files, line by line. Here is my code that is supposed to read lines of two file, into string variables, I assume, and then write them into third file: *line of first file line of second file .... so on …

Member Avatar for marnun
0
263
Member Avatar for кодирование

First of all, just registered and this forum looks great! PROBLEM: My program which I wrote in Code::Blocks, has compiled fine and has worked fine, but when I run the outputted file called (BINDED.exe) it shows a very quick console window then closes, I think this is due to the …

Member Avatar for georgeduroa
0
168
Member Avatar for pattmorter

a friend asked me to help him with his lab. the lab involves opening a file and adding the numbers in the file together displaying how many even and how many odd numbers there are. I have the file "textinput.txt" in the directory with the .cpp file but when i …

Member Avatar for pattmorter
0
287
Member Avatar for ThomsonGB

//////////////////////////////////////////////////////////////////////////////////////// // In this little project I am trying to learn to get and manipulate data from // a file input using fstream strings I also wanted to use the formating available // with the printf and related string handling methods. I have a question in regards // to the …

Member Avatar for ThomsonGB
0
256
Member Avatar for seamus400

I've found some similar posts on opening different files with the same file stream but they are difficult to understand. I'm trying to figure out for a larger project why I can't use the same file stream as in this example and what an alternative solution may be. And yes …

Member Avatar for seamus400
0
4K
Member Avatar for yoni0505

I had a problem with some program I wrote that edit specific values within a specific file. When I saved the values, using fstream's write() function, everything between these values became null. I've looked again in the I/O tutorial - [URL="http://www.cplusplus.com/doc/tutorial/files/"]http://www.cplusplus.com/doc/tutorial/files/[/URL] and saw that they use memory block at the …

Member Avatar for yoni0505
0
341
Member Avatar for yoni0505

Hi I have a problem with a code I made, some save editor for some game. The code suppose to write 2 bytes to a specific offset in some file. The file's short integers are saved as little endian. everything works fine, but when one of the integers equal 10, …

Member Avatar for yoni0505
0
201
Member Avatar for yozzie

Alright - this is my conundrum. As a noob to C++ I am only in chapter 9 of my book, having just covered object oriented programs and the exciting world of vectors and arrays. I have an assignment that asks me to run a loop to get and calculate a …

Member Avatar for yozzie
0
2K
Member Avatar for whodoes21

ok so what does this do.. 1.) read the text file(most likely a c++ code in text form) line by line and display it line by line... 2.) (as the title says) check for syntax errors. ( only minor ones like missing ";" or a lack of closing braces) soooo..... …

Member Avatar for ravenous
0
2K
Member Avatar for martin11ph

I need a program that opens a sample program and counts the number of reserved words, operands and operators. Operands and operators are easy to distinguish. My problem is how do I determine the reserved words there? One solution I thought of is to create a separate text file that …

Member Avatar for mrnutty
0
149
Member Avatar for Peram

I already know how to use fstream. I know to save the value variables to a file, and I also know how to make the program display the information in the file, but my problem is that it saves the content of the variable, not the variable itself. Here's what …

Member Avatar for Peram
0
227
Member Avatar for ranko_6

Trying to write a simple program that will read data but keep stumbling upon the fact that I kinda can't limit the amount that is read. I have simple student.dat file which is filled ATM with nothing else but simple string "somethinginside", without quotes. When I do this on each …

Member Avatar for ranko_6
0
202
Member Avatar for fire_

I need your help... Again... How can i combine reading from file with [iCODE]std::getline(file, std::string);[/iCODE] and [iCODE]UpdateData(FALSE);[/iCODE] ? UpdateData() accepts only CString and getline only std::string, and then i try to use it like that: [CODE]std::string readbuff; int length; std::ifstream file("file.txt"); while(getline(file, str)) { length = str.length(); for(int i=0; i<length; …

Member Avatar for fire_
0
604
Member Avatar for Vllinator

Hi im writing a function in a program that lets the user delete a specific record in a file, the user is also able to recover this record. The easiest way i found is when the record is deleted, the record will be set to deleted using bool. Then in …

Member Avatar for Ancient Dragon
0
2K

The End.