I have a .txt file of a page from a novel with all lowercased letters. I need to tell the program to capitalize the first char after the delimiter ". " Where am I supposed to implement the toupper function with that delimiter?
//This program reads an article in a text file, and changes all of the
//first-letter-of-sentence-characters to uppercase after a period and
//whitespace.
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>//for toupper
usingnamespace std;
int main()
{
//Variable needed to read file:
string input;
fstream file;
//Open the file:
fstream dataFile("eBook.txt", ios::in);
if (!dataFile)
{
cout << "Error opening file.\n";
return 0;
}
//Read lines, and toupper the first char right after the ". " delimiters:
getline(dataFile, input, ". ");//error: no instance of overloaded function "getline"
//matches the argument list
//argument types are:(std::fstream, std::string, int)
while (!dataFile.fail())
{
cout << input << endl;
getline(dataFile, input);
}
//Close the file:
dataFile.close();
return 0;
}
Note that my biggest problem is capitalizing the first sentence char only, and not the entire sentence string.
Then there is the byte way, where if your letter is less than 91 bytes, its a capitol, and if it is over it, it is undercase. And all you have to do is subtract the undercase by 32 bytes. (more accurate: 65-90 = upper, 97-122 = under). This will look like obfuscation though, with magical random numbers that just seemingly work.
getline takes a character, a single character, as delimeter. You are trying to pass a string which is not possible.
What can you do:
1) Separate strings based on '.' delimeter. After that manually check existense of space after it and use toupper if needed.
2) Use one of Boost faculties. Namely Boost::split.