Linked Questions

741 votes
9 answers
879k views

I need to read a whole file into memory and place it in a C++ std::string. If I were to read it into a char[], the answer would be very simple: std::ifstream t; int length; t.open("file.txt"); /...
Escualo's user avatar
  • 42.5k
112 votes
7 answers
285k views

Possible Duplicate: What is the best way to slurp a file into a std::string in c++? In scripting languages like Perl, it is possible to read a file into a variable in one shot. open(...
sonofdelphi's user avatar
  • 2,036
60 votes
3 answers
156k views

What is a good approach to read the whole file content in a buffer for C++? While in plain C I could use fopen(), fseek(), fread() function combination and read the whole file to a buffer, is it ...
vard's user avatar
  • 2,302
0 votes
2 answers
8k views

Possible Duplicate: What is the best way to slurp a file into a std::string in c++? Im trying to store a whole text file as a string, how can I dynamically store any amount of characters the text ...
theUser's user avatar
  • 1,396
-1 votes
1 answer
9k views

I'm looking for a way to way to read files in C++ I can write files, but here's where I'm stuck at: ifstream readfile; readfile.open("C:/Users/Crazy/Desktop/Useless.txt") I 've seen people do things ...
Katido 622's user avatar
7 votes
2 answers
442 views

Possible Duplicate: What is the best way to slurp a file into a std::string in c++? I assumed there would be a question like this already, but I couldn't find one. So here goes my question. What ...
danijar's user avatar
  • 34.5k
-3 votes
2 answers
1k views

Possible Duplicate: What is the best way to slurp a file into a std::string in c++? I'm trying to imitate PHP's file_get_contents() function for C++. However, when I convert a char array into a ...
Rookie's user avatar
  • 4,154
0 votes
1 answer
2k views

This may be trivial, but I'm new to C++ and an getting confused here. I have the method: bool load_database_file( const std::string& filename, std::string& contents ) { std::ifstream is ...
Brett's user avatar
  • 12.1k
0 votes
1 answer
316 views

My function reads a file and puts it into a string in order for me to process it. I need to read just before EOF, obviously. The problem is that the EOF character is also put inside the string and I ...
A O's user avatar
  • 65
-1 votes
1 answer
441 views

I'm trying to learn Google's c++ compression library Snappy. It requires that data be loaded into an std::string to compress or decompress it. How can I go about opening a file and loading the data ...
Kahless's user avatar
  • 1,264
1 vote
2 answers
156 views

I would like to read and display the content of a file entered by user at run-time My code : #include<iostream> #include<fstream> #include<stdio.h> using namespace std; int main() { ...
Poorvaja's user avatar
-2 votes
1 answer
138 views

I have a university assignment and i need to have some sort of function that detects the presence of a binary sequence (in my case, it should be a "virus" signature -> the assignment is to create some ...
Pavlo's user avatar
  • 1
-1 votes
2 answers
107 views

I am writing a method which requires reading a file and putting all its contents into a string variable. This is what I have tried: unsigned int ShaderHandler::CompileShader(unsigned int shaderType, ...
M.E.'s user avatar
  • 5,695
0 votes
1 answer
93 views

I want to read the contents of a file into a string. string contents(size, '\0'); -> size was determined above using the file.seekg and file.tellg. file.read((char*) contents.data(), size); Now, I ...
ecstrema's user avatar
  • 721
-5 votes
1 answer
126 views

Instead of writing cout hundreds of times, I want to read from a text file? I don't get how to simply read from a text file, which only has words in it? Many thanks!
Chris Beldam's user avatar

15 30 50 per page
1
2 3 4 5
7