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. ...
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...
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 ...
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....
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...
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...
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()...
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...
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 ...
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 ...
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,...
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")...
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...
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...
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...
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...
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:...
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...
© 2022 - 2025 — McMap. All rights reserved.