Linked Questions
100 questions linked to/from How do I read an entire file into a std::string in C++?
741
votes
9
answers
879k
views
Read whole ASCII file into C++ std::string [duplicate]
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"); /...
112
votes
7
answers
285k
views
Read file-contents into a string in C++ [duplicate]
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(...
60
votes
3
answers
156k
views
C++ read the whole file in buffer [duplicate]
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 ...
0
votes
2
answers
8k
views
How do I store a variable length string in C/C++ [duplicate]
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 ...
-1
votes
1
answer
9k
views
Reading Files in C++ [duplicate]
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 ...
7
votes
2
answers
442
views
Shortest way to read Textfile to String [duplicate]
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 ...
-3
votes
2
answers
1k
views
How to read any file safely into a string? [duplicate]
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 ...
0
votes
1
answer
2k
views
How can I assign a std::string from a char * [duplicate]
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 ...
0
votes
1
answer
316
views
How to read just before EOF from a file and put it into a string? [duplicate]
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 ...
-1
votes
1
answer
441
views
Push binary contents of file to std::string for use with Google's Snappy [duplicate]
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 ...
1
vote
2
answers
156
views
How to read total file line by line and set value to string [duplicate]
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()
{
...
-2
votes
1
answer
138
views
Reading the binary content of a file [duplicate]
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 ...
-1
votes
2
answers
107
views
How do I read a file in C++ and write contents into a string? [duplicate]
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, ...
0
votes
1
answer
93
views
Cpp create string creation without initialization [duplicate]
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 ...
-5
votes
1
answer
126
views
Read from file C++ (Simple) [duplicate]
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!