Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {
- string filename;
- cout << "Enter the name of the file: ";
- cin >> filename;
- ifstream file(filename);
- if (!file.is_open()) {
- cerr << "Error: could not open file " << filename << endl;
- return 1;
- }
- string line;
- while (getline(file, line)) {
- string sentence = "";
- for (int i = line.length() - 1; i >= 0; i--) {
- if (line[i] == ' ' || i == 0) {
- if (i == 0) {
- sentence = line[i] + sentence;
- }
- for (int j = 0; j < sentence.length(); j++) {
- cout << sentence[j];
- }
- cout << endl;
- sentence = "";
- }
- else {
- sentence = line[i] + sentence;
- }
- }
- cout << endl;
- }
- file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement