Questions tagged [fstream]

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

The C++ standard library type std::fstream is an iostream type for reading and writing files.

The objects of this class internally maintain a pointer to a std::filebuf object (derived from std::streambuf) that can be obtained/modified by calling the rdbuf member function. The filebuf transfers characters to/from a file and performs any necessary conversion between the on-disk format and the in-memory representation.

For questions specific to fstream use this tag or , , or for more general questions use , , or .

2840 questions
0
votes
1 answer

Reading Files into a Structure of Data

I have some sample code and I cannot figure out why it's not reading in each line properly. The logic looks fine, but I suspect that it might be some buffer issue in my file object after I read file into num_of_shades. colors.cpp #include…
0
votes
3 answers

Store string into a variable in next line of a file

I just started to refresh myself on the library in C++, and I'm attempting to store the first line of my text file into 3 integer variables, all split with spaces. The second line of the text file has a string and I'm trying to get my…
0
votes
3 answers

C++ can't write to file

I'm struggling with this code for some time now. To simply put my question I want to read 2 Names from file1 and then write it to the line of the file2. It's reads the name just fine but it doesn't write it to the file2. #include…
0
votes
1 answer

what does testing an "stream >> char" do?

I have this snippet of code, which has the purpose of defining the >> operator for a struct point (it's not the whole function, just the beginning). struct Point { int x; int y; }; The code snippet istream& operator>>(istream& is,…
AviouslyAK
  • 107
  • 5
0
votes
0 answers

Why does C++ operator<< in ifstream omit certain data?

In the code below, I have a collection of binary files that are created from downloading parts of an iso file. Individually they are just a collection of bytes with no semantics of their own. I wish to merge them into one file, back to the original…
Liang Wang
  • 41
  • 3
0
votes
2 answers

C++ write and read a file in binary mode

I want to create a binary file in /dev/shm/uploaded and open a file in binary mode and write data into it. std::string string_path = "/dev/shm/uploaded/"; std::string filename = "download_file.out"; std::string tmpStr = "The quick brown…
liv2hak
  • 14,472
  • 53
  • 157
  • 270
0
votes
1 answer

Read and Store CSV Data

i have a data like this; InvoiceNo;StockCode;Description;Quantity;InvoiceDate;UnitPrice;CustomerID;Country A;B;C;D;E;F;G;H A2;B2;C2;D2;E2;F2;G2;H2 . . . A500000;B500000;C500000;D500000;E500000;F500000;G500000;H500000 I am using that code to read…
OSentrk
  • 58
  • 1
  • 1
  • 9
0
votes
0 answers

How fix my codeblocks compile programm use fstream, cannot open files large 20 mbs?

#include #include #include using namespace std; int main(){ char fileInputPath[256] = "D:\25mb.file"; ifstream fileInput(fileInputPath, ios::in|ios::binary); if (fileInput.is_open() != true) cout <<…
Anonim
  • 1
  • 2
0
votes
0 answers

Error converting a binary CSV file to a TXT file

My problem is that i'm getting this error: (terminate called after throwing an instance of 'std::invalid_argument' what(): stoi) I have to input a binary CSV file run the syntax and save the output in a TXT file. Any help would be…
0
votes
0 answers

Fstream read function does not write data into indicated address

My problem is concerning the following code: void znajdzNastepnyElement(fstream& baza, unsigned int& licz_zaglebienie, unsigned long long int& kursor, unsigned long long int& poczatek_elementu, const unsigned int& dl_baza) { char znak = '\0'; …
drydre
  • 3
  • 2
0
votes
2 answers

How to read a string from a file with space within it c++

i wrote a code for searching a string in a file. Actually, i put my data in my file like this: alex booth,15,1 (fullname with space, age, id). There isn't any problem with saving data in the file, i got a big problem in searching for a string in…
Alireza Kiani
  • 410
  • 1
  • 5
  • 11
0
votes
2 answers

Exception thrown while reading elements from a binary file (Exception thrown: read access violation. _Pnext was 0xB414D4.)

first of all i made a simple class: class test { public: test(string name="",int age=0); void getData(); void show(); private: string name; int age; }; test::test(string name,int age) { this->age = age; this->name =…
0
votes
0 answers

Opening text file first 10 line and then more lines if needed

i want to make a code to open .txt file first 10 lines to find a specific file and then if I'm not sure if that's the file which I need it will output a specific number of lines to find a required file. But when I'm typing in the lines number it…
user12538722
0
votes
1 answer

When writing from the buffer to the file, the file becomes one character larger

I use zlib library to compress data from strings and get compressed data also in strings. I load and unload compressed data using fstream. The problem is that sometimes it happens that when a line is written to a file, it becomes one byte larger and…
0
votes
1 answer

When should you use the fail function for streams?

For my program, I'm supposed to read in a file "sales.txt" that contains a salesperson's name and the dollar amount of a sale. The file is sorted alphabetically so that if a person made multiple sales, their name will appear consecutively with the…
Caitlyn T
  • 33
  • 2
1 2 3
99
100