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
0 answers

attempting to append text to a (fake) host file in C++ 11

I'm essentially attempting to append text to a host text file on MacOS (mojave) and it's not working. I created a fake host file located at: /public/etc/hosts (real host file is private/etc/hosts) and all I'd like to do in this scenaro is append…
0
votes
1 answer

Stop Words in C++

The following C++ program takes two text files, stop_words.txt, and story.txt. It then removes all the stop word occurrences in the story.txt file. For instance, Monkey is a common name that may refer to groups or species of mammals, in part, the…
user840
  • 134
  • 1
  • 13
0
votes
1 answer

Read only user's names from txt file [C++]

ifstream file; file.open("Data.txt"); string name; while (file >> name) { cout << name << endl; } So i have a text file where the following information is stored about a user: Name, Weight, Height and previous heights. How would i only output…
Snappy
  • 5
  • 2
0
votes
1 answer

std::fstream different behavior on msvc and g++ with utf-8

std::string path("path.txt"); std::fstream f(path); f.imbue(std::locale(std::locale::empty(), new std::codecvt_utf8)); std::string lcpath; f >> lcpath; Reading a utf-8 text from path.txt on windows fails with MSVC compiler on windows in…
user3819404
  • 611
  • 6
  • 18
0
votes
1 answer

C++ problem trying to open a .txt file using Ifstream

This small bit of code is designed to look through a text file and identify account numbers that have already been written so that later on in my program, you can find the correct account without the error of two accounts with the same account…
0
votes
1 answer

Read from the file from different functions

I'm trying to read from the same file from another function but it doesn't work. I guess the problem is that I'm trying to read from ifstream &input but I don't know the other way to implement that #include #include using…
0
votes
0 answers

read 32 bit integer from binary file in c++

i'm trying to read a 32 bit integer from a binary file in c++. My goal is to obtain something similar to the c# BinaryReader.ReadInt32() method. As specified here, this c# method reads a 4 bytes signed integer. I have verified that my input file is…
rekotc
  • 595
  • 1
  • 10
  • 21
0
votes
1 answer

C++ data file not reading correctly when introducing ofstream?

Ok so, this is gonna be a long one... Explanation of what the project is supposed to do: My final project is a bank teller system that stores all the account related data on a text files. The file in question, "accounts.txt", is where all the…
0
votes
0 answers

Read an intex hex file line by line and manipulate the data

I am reading data from Intel hex format file after opening it in binary mode and then creating a data (unsigned char)buffer and storing all the data in that (unsigned char)buffer in hex format. I'm facing issue when the length of the data line is…
0
votes
1 answer

How can I open a file in c++, without erasing its contents and not append it?

I am trying to find a way using which I can Edit the contents in a binary file, without reading the whole file. Suppose this is my file abdde And I want to make it abcde I tried following:- Attempt 1) ofstream f("binfile",…
Rishav Bhowmik
  • 57
  • 1
  • 11
0
votes
1 answer

File read exception while reading MAC address

We have a common file operation class which will do all basic file operations. So I used same file operation class to read MAC address from Linux machine, and it throws basic_ios::clear:iostream exception. Here is the code which will be doing the…
Gilson PJ
  • 3,443
  • 3
  • 32
  • 53
0
votes
1 answer

How to use a single fstream for creation, reading and writing a file

I would like to access a file through fstream with the following requirements: If the files does not exists, it create it The file can be read (from pos 0) The file can be (over)written (from pos 0) Without closing and re-opening the…
Adrian Maire
  • 14,354
  • 9
  • 45
  • 85
0
votes
0 answers

How can I open files using filestream in Notepad++ and cmd? C++

I'm confused about how to open/access a file using Notepad++ and the cmd with MinGW compiler. I understand the file needs to be in the same scope however, I'm not sure where. I have tried placing the .txt file in my Documents folder which also holds…
Manny
  • 43
  • 6
0
votes
1 answer

How to Read Numerical, Minute and Second Values from File, While Writing Values *Exactly As Given* To Other File

First off, is it possible? To extrapolate the question: I'd like to read some integers from a file, which is relatively simple for me. However, when I read these values, which are formatted: "123 17 24 55 04 30 09" for example, my written output…
0
votes
0 answers

C++ | Trying to create a "Modify" option in C++ doesn't work

I'm working in a little project about a Coffe Shop. I'm trying to develope an option to modify any item in the "ListaDeProductos.dat" file, which store all the items created by the user. I found a very old code I made it 4 years ago, lol, and there…
1 2 3
99
100