How to make sentence a new paragraph in c++ text file

I am writing my code here..I have to modify my output text file and convert every sentence into paragraph. I ran it its copying whole text but not paragraph after dots.
#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;
void copyText(ifstream& intext, ofstream& outtext, char& ch);
int main()
{
int count = 0;
char ch;
ifstream infile;
ofstream outfile;

infile.open("textin.txt");
outfile.open("textout.out");
while(infile) {
copyText(infile, outfile, ch);
infile.get(ch);
}
while(infile) {
if(ch == '.')
{
cout << '\r';
infile.get(ch);

}
}
system("pause");
return 0;
}

void copyText(ifstream& intext, ofstream& outtext, char& ch)
{

while(ch != '\n') {
outtext << ch ;
intext.get(ch);
}
outtext << ch;
}
Last edited on
can anyone help
I thing getline is bettern than get

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
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	
	ifstream ifs("textin.txt");
	ofstream out("textout.out");
	if(!ifs)
	{
		cerr << "Unable to open the file: " << filename  << endl;
		return -1;
	}
	if(!out)
	{
		cerr << "Unable to open file  textout.out for writing " << endl;
	}
	string str;
	while( getline(ifs,str) ) // read each line till \n is encountered
	{	 
		out << "\t" << str << endl;  
	}

	ifs.close();
	out.close();
}


 cat textin.txt 
Vision therapy, also known as vision training, is used to improve vision skills such as eye movement control and eye coordination. 

It involves a series of procedures carried out in both home and office settings, usually under professional supervision by an orthoptist or optometrist.[1] Vision therapy can be prescribed when a comprehensive eye examination indicates that it is an appropriate treatment option for the patient. 

The specific program of therapy is based on the results of standardized tests, the needs of the patient, and the patient's signs and symptoms. Programs typically involve eye exercises and the use of lenses, prisms, filters, occluders, specialized instruments, and / or computer programs. The course of therapy may last weeks to several years, with intermittent monitoring by the eye doctor.[

$ cat textout.out 
	Vision therapy, also known as vision training, is used to improve vision skills such as eye movement control and eye coordination. 
	
	It involves a series of procedures carried out in both home and office settings, usually under professional supervision by an orthoptist or optometrist.[1] Vision therapy can be prescribed when a comprehensive eye examination indicates that it is an appropriate treatment option for the patient. 
	
	The specific program of therapy is based on the results of standardized tests, the needs of the patient, and the patient's signs and symptoms. Programs typically involve eye exercises and the use of lenses, prisms, filters, occluders, specialized instruments, and / or computer programs. The course of therapy may last weeks to several years, with intermittent monitoring by the eye doctor.[

Last edited on
Topic archived. No new replies allowed.