fstream provides an iostream interface for file I/O in C++.

learn more… | top users | synonyms

-1
votes
2answers
44 views

Writing a class object into a file using fstream and then read it

I want to make a class of a student and take 3 inputs information and make an output of this file. How to this? This is my try: #include <iostream> using namespace std; class Student{ ...
-4
votes
1answer
50 views

How do I open a .txt file in C++?

#include <iostream> #include <fstream> #include <string> using namespace std; int main () { string line; ifstream myfile("hey.txt"); myfile >> line; cout << ...
1
vote
2answers
86 views

How to read then edit file txt in C++

I know this question was asked here but I didn't find what I was looking for. The best answer I could find currently showed how to add something to a text file. How could I use fstream to either only ...
-1
votes
0answers
4 views

Using concept of Stack and Read data from file find a highest CGPA in c++? [closed]

//Variable string Person[150]; string CGPA[150]; void loadeddata(); main { loadeddata(); system("pause"); return 0; } void loadeddata() { stack obj; stack obj1; try{ ifstream ...
0
votes
1answer
28 views

Using fstreams throws an access violation after main returns

The following function works fine, showing a text file line by line to stderr: void load_text(std::string path){ ifstream f(path); char linebuff[100]; linebuff[99] = 0; while(!f.eof()){ ...
0
votes
2answers
50 views

Taking a long time to close fstream

Why is my fstream taking 30+ seconds to close after writing data to the file? The more I write, the longer it takes to close. fstream *writeReadStream = new fstream("/media/username/KODAK/file.bin", ...
0
votes
1answer
35 views

Sequential file initialization unexpected behavior

I'm trying to initialize a file with 100 empty records with the code below: void initializeInventory() { std::ofstream out("hardware.dat", std::ios::binary); Hardware h; for (int i = 0; ...
0
votes
2answers
51 views

C++11 - Move object containing filestream

I've got the following (simplified problem): class Stream() { std::ofstream mStr; public: Stream() : mStr("file", ofstream::out) {} Stream(const Stream & rhs) = delete; ...
0
votes
0answers
35 views

writing data to bin file?

I developed an application before. in there I read kinect skeleton data in a thread and store it in a queue and when the user press the save button I wrote the data into a Bin file. I have several ...
2
votes
2answers
49 views

Reading input from fstream

So it is a simple problem. Simply read input from a specific file. Use the input as a Celsius temperature and convert this temperature into Fahrenheit then print the results to the user. The problem ...
2
votes
4answers
81 views

Writing ASCII to file

I've been thinking about an easy way for a programmer to write down all ASCII characters. First I tried to print it in a console but it didn't show me all characters. So I tried to write it to a file ...
0
votes
1answer
35 views

ofstream trouble, how do i resolve this?

I am iterating over a map containing words as keys and to each word there are bunch of numbers assigned stored in vector<int> indicating on which line they were found. I am having trouble ...
-3
votes
0answers
37 views

Reading stuff from file and saving it into certain integers

I've got a code like this saveo.open("save.dat", std::fstream::out | std::fstream::trunc); saveo<<ept<<hp<<"\n"; saveo<<ept<<mana<<"\n"; ...
1
vote
1answer
17 views

C++ Program in Xcode not outputting simple text filer using outFile

I am running a program using this simple example code to output a text file. I am using Xcode and simply started a new C++ project from command line tools. For some reason the program does not output ...
0
votes
1answer
27 views

fstream directly access struct variable

I know how to read and write a complete struct with fstream. But just for curiosity, is there a way to access (read or write) a variable directly? I have never seen somebody doing this. aStruct * ...
0
votes
3answers
81 views

Having problems with 0x0A character in C++ even in binary mode. (interprets it as new file)

Hi this might seem a bit noobie, but here we go. Im developing a program that downloads leaderboards of a certain game from the internet and transforms it into a proper format to work with it ...
0
votes
1answer
47 views

Qt - QFile - How to read only first word in every line

How can I read only first word in every line in a text file while using QFile in Qt? Thanks.
4
votes
1answer
61 views

Updating the end of the file in c++ fstream

I wrote this code: #include <fstream> #include <iostream> using namespace std; struct Man { int ID; char Name[20]; }; void Add(); void Update(); void Print(); int main() { ...
0
votes
2answers
41 views

How do I use quotation marks in fstream?

I want to output a line into a .plt file that says "one-D Hydro" with the double quotation marks and so far I have this problem. #include <cstdlib> #include <fstream> using namespace ...
0
votes
1answer
96 views

trying to sort a txt file in c++ using a function and writing it back out to a txt file

void insertionSort (int arrtosort[], int size) { int temp = arrtosort[0]; for(int i = 1; i < size; i++) { temp = arrtosort[i]; int j = 0; for(j = i; j > 0; j--) if(temp ...
3
votes
2answers
78 views

Ofstream returning garbage. Cout works… Why doesn't ofstream?

So I'm trying to design a program that inputs a file and then reads through the lines and takes each line and outputs info about it to a new file. I have it all down... except! All my .txt files are ...
-2
votes
1answer
58 views

C++ Ifstream Program - Error [closed]

I don't understand what I am doing wrong here. I also don't understand how I am supposed to use ifstream to read in the city and country strings when there has been no file created with that ...
0
votes
2answers
70 views

ifstream ignoring spaces and new lines - why?

So I am writing a simple program just trying to understand why it is ignoring spaces (it treats them as new lines) and why it does not account for new lines. Language: C++ Platform: Kubuntu 13.04 ...
0
votes
0answers
91 views

[Can't figure out][C++] Access violation error using ofstream/fstream?

I am writing to a file, using ofstream. The writes are very rapid for one thing, file is closed and opened extremely frequently. Below is the code: if( !(IS_ERROR(wcstombs_s( (size_t*)&out, ...
-2
votes
2answers
75 views

opening c++ txt file and reading individual digits into int array

I am trying to read a text file into an array of integers but my read doesn't affect anything and my array stays at its default value of 0, my code is as follows #include <iostream> #include ...
0
votes
1answer
46 views

Expecting eof but instead arbitrary data near eof

I have sought to discover the cause of unwanted trailing end-data in a file I am writing specific data into and do not believe I have made errors in writing to the file. The output looks like: ...
0
votes
2answers
58 views

ifstream wont read all integer

When i read TestData.txt file it gives me wrong output. What am i doing wrong. I am using int array so i can do MergeSort after saving data into array. TestData.txt ------------------- 31791 ...
1
vote
2answers
76 views

C++ : Read/Write Binary data to file when data is complex

How would I write/read data to a file in binary, if I also have to define how to save my data? I'm attempting to save some simple data structures out to a file in binary. For example, I have a ...
0
votes
0answers
10 views

Getting the same result when reading with stream

I'm trying to read in the 16bit sample values of a .wav file; int DEBUG_TRACKER = 0; for(long int s = filesize; s > 0; s = s - 400000){ int16_t leftsample = 0; int16_t rightsample = 0; ...
0
votes
0answers
63 views

File Input failure C++

I've been trying to grasp how reading and writing with the fstream class works, and I've become stuck. The program reads the magic number of the file correctly, and then suddenly fails to read an ...
1
vote
1answer
40 views

Load and save an HTML file with polish characters

I need to load an HTML template file (using std::ifstream), add some content and then save it as a complete web page. It would be simple enough if not for polish characters - I've tried all ...
0
votes
0answers
10 views

How is std::fstream with both in and out supposed to work?

I've just started wondering - how is actually std::fstream opened with both std::ios::in and std::ios::out actually supposed to work? What should it do? Write something to (for example) an empty file, ...
1
vote
1answer
29 views

Order of writing to an HTML file

Ok, the title is probably confusing (but I couldn't come up with a better one) - I've created a simple Logger class that outputs to an HTML file. The file has some stuff at the top (title, js/css ...
3
votes
3answers
86 views

What does std::ofstream::close() actually do?

This question: How to protect log from application crash? has lead me to another - what does std::ofstream::close() actually do? I know it calls flush() and that's one thing. But what else? What ...
1
vote
2answers
65 views

How to protect log from application crash?

I've created a simple logger which, well, logs everything of importance into a text file. I'm using std::ofstream but there's a problem - when the program doesn't close the file (call ...
-1
votes
2answers
36 views

how to call a cout function to ofstream output file

I have a function void displayList() that displays a list of a set. in the main function I also have ofstream outputFile(output.txt) how do I call displayList and prints it in output.txt? Thanks. ...
0
votes
0answers
5 views

Sending OutPut to two files from an array and a function

What am I doing wrong here? When I send this I am getting totally blank files? Do I need to re-work the array or is the function not actually sending anything to the files? This is homework so helpful ...
0
votes
1answer
46 views

fstream accepts folder path and is (`good()==1`)

#include<iostream> #include<fstream> int main() { std::string folderPath("./"); std::string fileFoo = folderPath + ""; std::string fileBar = folderPath + "nonexisting_file"; ...
1
vote
3answers
69 views

C++ Segmentation fault when working with <vector> and <fstream>

I was working with 3D vectors and everything worked perfectly. When I added and worked with ofstream files Segmentation Fault appeared. I don't understand the problem at all. The following code ...
0
votes
2answers
61 views

Reading Lines from File and Storing in Separate String Variables

I am creating a bank terminal for an assignment. It has the ability to add clients with each client containing 5 different variables for name, address, social#, employer, and income. Those variables ...
0
votes
3answers
71 views

Problems using strtok() and stringstream

I've been fiddling with this for a while now, and all it returns is first two numbers in the 'save.rp' file on separate lines, int characterPosition [2] = {0,0}; string convToStr(char *ch) { ...
1
vote
2answers
56 views

optimization of sequential i/o operations on large file sizes

Compiler: Microsoft C++ 2005Hardware: AMD 64-bit (16 GB) Sequential, read-only access from an 18GB file is committed with the following timing, file access, and file structure ...
1
vote
1answer
69 views

c++ fstream don't print symbols like ρ and Δ to file correctly

I get a messed up result when using fstream to print these symbols to file. using: file << "Δ" << endl; This works fine in Linux, but when i compilled it for windows it don't work. Is ...
0
votes
1answer
124 views

Writing to an output file using fstream in C++ [closed]

Assuming you have the proper headers and are using namespace std; is this somewhat correct in terms of using fstream to output a string to some output file? I only included the relevant file API parts ...
3
votes
1answer
94 views

unread a file in C++

I am trying to read files that are simultaneously written to disk. I need to read chunks of specific size. If the size read is less than the specific size, I'd like to unread the file (something like ...
0
votes
2answers
57 views

trouble reading binary data

The reader and writer #include<string> #include<fstream> #include<memory> class BinarySearchFile{ BinarySearchFile::BinarySearchFile(std::string file_name){ // ...
0
votes
1answer
104 views

std::fstream::write && std::fstream::putc std::ios::binary

I suspect I am not even creating and opening a file for binary I/O using std::fstream BinarySearchFile::BinarySearchFile(std::string file_name){ // concatenate extension to fileName ...
0
votes
1answer
37 views

Minesweeper C++ - trouble building array from file

For homework I'm making a simple textual minesweeper program. I need to read the array parameters from a text file that will be randomly generated, but to get the program built first I'm using a known ...
1
vote
1answer
89 views

What are the options for safe use of fstream with many threads

I am creating my own IOsystem, which is using fstream. There will be many threads and my question is how can I keep it safe which means to allow multiple read from one file but keep writing exclusive. ...
1
vote
2answers
111 views

C++ , reading & writing to the same file after processing

I am looking for a clean c++ solution to read and write to the same file after processing the string read from ifstream. For example this is what I have in mind std::ofstream ofs("test.txt", ...

1 2 3 4 5 13
15 30 50 per page