ifstream Questions

4

Solved

I have a program that basically reads a text file and counts the number of occurrences of each word on each line. Everything works properly when reading from a text file using an ifstream, however,...
Notorious asked 14/4, 2014 at 0:45

3

Solved

I read an answer here showing how to read an entire stream into a std::string with the following one (two) liner: std::istreambuf_iterator<char> eos; std::string s(std::istreambuf_iterator&...
Mutt asked 27/10, 2014 at 14:3

6

I'm using C++ fstream to read a config file. #include <fstream> std::ifstream my_file(my_filename); Right now, if I pass the path of a directory, it silently ignores this. E.g. my_file.goo...
Arundinaceous asked 27/3, 2015 at 21:3

4

Solved

I want to read unsigned bytes from a binary file. So I wrote the following code. #include <iostream> #include <fstream> #include <vector> #include <istream> std::string fi...
Polyzoic asked 2/3, 2009 at 23:0

6

Solved

I've been all over the ifstream questions here on SO and I'm still having trouble reading a simple text file. I'm working with Visual Studio 2008. Here's my code: // CPPFileIO.cpp : Defines the e...
Aeroneurosis asked 28/4, 2009 at 16:32

3

Solved

The well known way of creating an fstream object is: ifstream fobj("myfile.txt"); ie. using a filename. But I want to create an ifstream object using a file descriptor. Reason: I want to exe...
Microchemistry asked 19/5, 2012 at 17:48

1

Solved

A standard idiom is while(std::getline(ifstream, str)) ... So if that works, why can't I say bool getval(std::string &val) { ... std::ifstream infile(filename); ... return std::getline...
Hermelindahermeneutic asked 14/3, 2022 at 22:41

7

Solved

Specifically I'm interested in istream& getline ( istream& is, string& str );. Is there an option to the ifstream constructor to tell it to convert all newline encodings to '\n' under t...
Ramadan asked 22/5, 2011 at 16:29

8

Solved

How can I count lines using the standard classes, fstream and ifstream?
Radiotransparent asked 18/6, 2010 at 20:19

2

Solved

I made some tests with std::ifstream on MSVC, when reading binary files. I have big performance differences between char and unsigned char data types. Results when reading a 512 MB binary file: Dur...
Lipman asked 9/8, 2021 at 22:10

4

Solved

What's the difference between these two? Isn't the in flag object thing redundant? Thanks. std::ifstream file1("one.bin", std::ifstream::in | std::ifstream::binary); std::ifstream file2("two.bin"...
Yellowtail asked 18/9, 2011 at 18:18

3

Solved

In C++ file handling, I came across ifstream, ofstream and fstream. Can anyone tell me the main difference between these?
Carnay asked 21/5, 2021 at 5:10

2

Solved

I have a file that contains text, I would like to get each line from this file into a std::wstring variable.If I do this I get an error, so is it possible to use std::wstring or I'm obligate to use...
Tengler asked 19/11, 2015 at 14:26

3

Solved

I am trying to use an ifstream to open a named pipe that will eventually have data written to it. std::cout << "Opening " << name << std::endl; std::ifstream manual_shutdown_file...
Brambling asked 4/3, 2013 at 23:18

1

Solved

I have a function do_something that reads unsigned characters from a stream. The stream can be created from a file given the file name. Or it can be created from the given string by considering it ...
Pindaric asked 17/7, 2020 at 18:28

5

I want the user to give me the full path where the file exists and not just the file name. How do I open the file this way? Is it something like this: ifstream file; file.open("C:/Demo.txt", ios:...
Emetic asked 9/5, 2009 at 10:27

3

Solved

I have the following code and it works pretty good (other than the fact that it's pretty slow, but I don't care much about that). It doesn't seem intuitive that this would write the entire contents...
Closestool asked 26/1, 2010 at 18:48

0

I'm was writing some interfacing code to call c++ routines from fortran which is why I dumped the methods into an extern "C" block. When compiling with g++.exe (x86_64-win32-seh-rev1, Built by MinG...
Idaidae asked 4/5, 2020 at 20:56

1

Lets say I have a code to compute the size of a file : std::ifstream ifs(path, std::ifstream::ate | std::ifstream::binary); unsigned int size = ifs.tellg(); ifs.close(); Most of the time in C++,...
Agnes asked 31/1, 2020 at 11:1

3

Solved

I think this should be quite simple, but my googling didn't help so far... I need to write to an existing file in C++, but not necessarily at the end of the file. I know that when I just want to a...
Ryurik asked 4/6, 2015 at 11:37

4

Solved

I am trying to read from a text file of students and assign each line to a struct data member. The text file structure is as follows: Name,Student code, Ability,Consistency,Program name:Subject l...
Duramen asked 21/8, 2019 at 7:26

5

Solved

Im trying to read the whole file.txt into a char array. But having some issues, suggestions please =] ifstream infile; infile.open("file.txt"); char getdata[10000] while (!infile.eof()){ infile....
Tree asked 7/12, 2010 at 3:10

4

Solved

Here's probably a very noobish question for you: How (if at all possible) can I return an ifstream from a function? Basically, I need to obtain the filename of a database from the user, and if the...
Devanagari asked 8/3, 2010 at 4:58

2

Solved

Should I close a file when it wasn't able to open? Should I write this: std::ifstream file(DATA_PATH); if (!file.good()) //File doesn't exist { //do something } else //file exists { //do someth...
Lillielilliputian asked 22/1, 2019 at 20:51

3

Solved

I'm trying to do operations per-line of a text file, and the way I have it right now, my ifstream object isn't detecting the \n character for each line, which is required for this project. Here's h...
Haughay asked 29/3, 2013 at 15:59

© 2022 - 2025 — McMap. All rights reserved.