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,...
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&...
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...
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...
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...
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...
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...
8
Solved
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"...
3
Solved
In C++ file handling, I came across ifstream, ofstream and fstream. Can anyone tell me the main difference between these?
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...
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:...
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...
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++,...
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...
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....
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...
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...
3
Solved
1 Next >
© 2022 - 2025 — McMap. All rights reserved.