
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
How to read file content into istringstream in C++?
Here is a C++ program to read file content into isstringstream in C++.
Example
#include <fstream> #include <sstream> #include<iostream> using namespace std; int main() { ifstream is("a.txt", ios::binary ); // get length of file: is.seekg (0, std::ios::end); long length = is.tellg(); is.seekg (0, std::ios::beg); // allocate memory: char *buffer = new char [length]; // read data as a block: is.read (buffer,length); // create string stream of memory contents istringstream iss( string( buffer ) ); cout<<buffer; // delete temporary buffer delete [] buffer; // close filestream is.close(); }
Output
hi tutorialspoint
- Related Articles
- C# Program to Read the Content of a File Line by Line
- How to read a file into a string in Golang?
- Read whole ASCII file into C++ std::string
- Write a program in Python to export a given dataframe into Pickle file format and read the content from the Pickle file
- How to read a CSV file and store the values into an array in C#?
- How to convert the content of the file into uppercase or lowercase?
- Golang program to read the content of a file line by line
- How to read a text file with C++?
- How to read text file into a list or array with Python?
- C# Program to read contents of a file into a string at once
- How to read a JSON file into a DataFrame using Python Pandas library?
- How to read CSV file in Python?
- How to read JSON file in Python
- What is the best way to read an entire file into a std::string in C++?
- How to put a Pandas DataFrame into a JSON file and read it again?

Advertisements