Re-output a file with capitalized-first-char sentences

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  //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
using namespace 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.
Last edited on
This isn't beginners stuff man...
The long but will work way is by:
1
2
3
4
5
6
7
switch((*str.begin()))
{
  case 'a': (*str.begin()) = 'A'; break;
  case 'b': (*str.begin()) = 'B'; break;
  case 'c': (*str.begin()) = 'C'; break;
  //...
}


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.
Topic archived. No new replies allowed.