ifstream Questions

4

Solved

I did a sample project to read a file into a buffer. When I use the tellg() function it gives me a larger value than the read function is actually read from the file. I think that there is a bug. ...
Minneapolis asked 10/4, 2014 at 10:8

1

Solved

I'm reading a file using std::ifstream: printf("Before stream initialization\n"); ifstream stream(file_path, ios::binary); printf("Stream initialized\n"); ifstream::pos_type position = stream.tell...
Airfield asked 21/11, 2018 at 22:47

2

Solved

I'm trying to read binary data from a file using ifstream. Specifically, I'm trying to populate this "Header" struct with data read from a file: struct Header { char id[16]; int length; int co...
Servile asked 5/3, 2014 at 8:25

1

Solved

I am using C++ 11 to copy a file this way: std::ifstream src(srcPath, std::ios::binary); std::ofstream dst(destinationPath, std::ios::binary); dst << src.rdbuf(); I am creating a new file ...
Afrikaner asked 24/7, 2018 at 6:59

4

Solved

Do I need to manually call close() when I use a std::ifstream? For example, in the code: std::string readContentsOfFile(std::string fileName) { std::ifstream file(fileName.c_str()); if (file....
Subinfeudation asked 14/4, 2009 at 14:59

2

Solved

I was running a MWE from here: http://www.cplusplus.com/reference/ios/ios/exceptions/ On my machine it does not catch the exception. Here is my code #include <iostream> #include <fstream&g...
Legality asked 25/10, 2016 at 17:48

2

Trying to read into a file the word, "beef" Later going and editing the contents of the file to whatever to user wants which will be stored in the string, "line" The file never displays and when I...
Seeger asked 29/3, 2018 at 19:20

6

Solved

I am currently writing a program in C++ which includes reading lots of large text files. Each has around 400.000 lines with in extreme cases 4000 or more characters per line. Just for testing, I re...
Inmesh asked 29/7, 2013 at 13:12

1

Solved

I had a typo (|| instead of |) and noticed such a code fails with GCC and compiles with Visual. I know that the second parameter of std::ifstream is an int. So theoretically, a bool has to be conv...
Raspings asked 23/11, 2017 at 13:19

1

Solved

i try to read parts of a binary file content into a string. Why a string? I need this for my message protocol (with protobuf). The following works very well: std::string* data = new std::string()...
Ultan asked 26/10, 2017 at 13:41

1

I'm having a hard time to parse an xml file. The file was saved with UTF-8 Encoding. Normal ASCII are read correctly, but Korean characters are not. So I made a simple program to read a UTF-8 t...
Pomeroy asked 8/4, 2017 at 15:59

3

Solved

I'm trying to read files stored in assets folder and its subfolders using std::ifstream in an iOS app written mostly in C++ (The same code is also used in other, non-iOS projects), but they're not ...
Chunky asked 30/11, 2010 at 12:31

2

Solved

My question is pretty simple, but I am having a hard time finding any info about this online. Is it possible to use ifstream to open a file from assets and/or resources using Android NDK? For ex...
Stollings asked 16/6, 2012 at 13:21

5

Solved

Ok, so this is the first time I've coded C++ in Xcode (I'm used to ObjC)and I've now started a programming course at my college. I'm trying to open a file (either hard coded or from user input in ...
Saransarangi asked 2/9, 2011 at 4:1

2

Solved

In an answer there was the following code: if (std::ifstream input("input_file.txt")) ; Which seems convenient, limiting the scope of the 'input' variable to where it's confirmed to be valid, h...
Dekeles asked 4/4, 2017 at 19:0

4

Solved

I have the following that will open a file for reading. However, I want to check to make sure that the file was open successfully, so I am using the fail to see if the flags have been set. However,...
Foote asked 6/6, 2011 at 16:49

2

Solved

I'm writing a program which takes several variables from a text file. When the program finds EOF, it ends entering data. int main() { int val, count = 0; ifstream fileIn; fileIn.open("num.txt")...
Mentalism asked 29/1, 2017 at 21:45

5

Solved

I'm currently writing a Simulated Annealing code to solve a traveling salesman problem and have run into difficulties with storing and using my read data from a txt file. Each row & column in t...
Lulululuabourg asked 21/2, 2009 at 13:12

4

Solved

i am trying to open a file with ifstream and i want to use a string as the path (my program makes a string path). it will compile but it stays blank. string path = NameOfTheFile; // it would be so...
Backbite asked 2/2, 2011 at 23:36

6

Solved

I want to have a variable of type istream which can hold either the contents of a file or a string. The idea is that if no file was specified, the variable of type istream would be assigned with a ...
Abundance asked 5/8, 2016 at 21:42

5

Solved

I have some code that uses ifstream to read some data from a file and everything works. Now I wish, without modifying some code, read this data from a memory, actually I have a char * that contain...
Anabelanabella asked 27/11, 2012 at 13:10

3

Solved

I am trying to help a friend with a project that was supposed to be 1H and has been now 3 days. Needless to say I feel very frustrated and angry ;-) ooooouuuu... I breath. So the program written i...
Lockout asked 15/9, 2013 at 15:36

1

Solved

I am writing test cases right now and I created some test files which I try to read. The absolute path is: /home/user/code/Project/source/Project/components/Project/test/file.dat but testing wit...
Supremacy asked 10/3, 2016 at 7:16

2

#include <fstream> #include <iostream> #include <exception> int main(int argc, char **argv) { try { std::ifstream sFile(argv[1]); sFile.exceptions(std::ios::badbit | std::ios:...
Virginiavirginie asked 4/2, 2016 at 1:16

2

Solved

original code #include<iostream> #include<fstream> using namespace std; int main() { ofstream arduino_output("/dev/ttyACM0"); ifstream arduino_input("/dev/ttyACM0"); int value; s...
Sluggish asked 14/1, 2016 at 19:45

© 2022 - 2025 — McMap. All rights reserved.