#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <iterator>
using namespace std;
string getResult(vector<string> val) {
bool flag = true;
for (int i = 0; i < val.size(); i++) {
// Iteration
string current = val[i];
for (int j = 0; j < current.size(); j++) {
if (current[j] != ' ') {
// If first word is uppercase
if (flag && isupper(current[j]) == 0) {
current[j] = toupper(current[j]);
val[i] = current;
}
flag = false;
}
}
flag = true;
}
string result;
for (int i = 0; i < val.size(); i++)
result += val[i] + ".";
return result;
}
int main() {
ifstream file("input.txt");
string str;
string file_contents;
if (!file.is_open()) {
cout << "Some problems with file...";
return -1;
}
while (getline(file, str)) {
file_contents += str;
file_contents.push_back('\n');
}
vector<string> array;
// split
istringstream is(str);
string s;
while (std::getline(is, s, '.'))
array.push_back(s);
cout <<"Current input: "<< str << endl;
string result = getResult(array);
cout << "After: " << result << endl;
return 0;
}
Запускаю его:
$: g++ -o prog main.cpp
$: ./prog
Получаю:
Current input:
After: