read char from text file c 2b 2b

Solutions on MaxInterview for read char from text file c 2b 2b by the best coders in the world

showing results for - "read char from text file c 2b 2b"
Tam
09 Jan 2017
1#include <iostream>
2#include <fstream>
3#include <vector>
4
5using std::cout; using std::cerr;
6using std::endl; using std::string;
7using std::ifstream; using std::vector;
8
9int main()
10{
11    string filename("input.txt");
12    vector<char> bytes;
13    char byte = 0;
14
15    ifstream input_file(filename);
16    if (!input_file.is_open()) {
17        cerr << "Could not open the file - '"
18             << filename << "'" << endl;
19        return EXIT_FAILURE;
20    }
21
22    while (input_file.get(byte)) {
23        bytes.push_back(byte);
24    }
25    for (const auto &i : bytes) {
26        cout << i << "-";
27    }
28    cout << endl;
29    input_file.close();
30
31    return EXIT_SUCCESS;
32}