Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements