Bulk deletion of extra empty lines in Word is implemented in C + +

Source: Internet
Author: User

Yesterday, Sister Z from the Internet under a large exam paper to print, found that the extra empty line is too much, so suddenly remembered that I was learning computer (I have no language, in fact, I am not really computer department, just a little hook. As a then, the elder brothers and sisters put me as an obligation of computer maintenance workers ... Oh, my gosh.  ), direct QQ to me, I opened a look, Khan Ah, how to engage AH.  Had not been done before, so I want to adjust the spacing between the lines, the result of a whole day just did not give to fix .... That was embarrassing. I have no words, Sister Z is angry ...

So, just get up today and prepare to use our C + + to get the problem .... Results a morning of fighting, finally saw the brow ....

Needless to say, the code comments are as follows: Let's see for ourselves ....


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace Std;

int main ()
{
int l;
BOOL m;
vector<string>a;
Char filename[100];
Char suffix[5]= ". txt"; The suffix word of txt text
String s,s1;

cout<< "Enter the filename to be cut" <<endl;
Cin.getline (filename,100);
L=strlen (filename);
if (filename[l-3]!= '. ') | | filename[l-2]!= ' t ' | | filename[l-3]!= ' x '
|| filename[l]!= ' t ')
{strcat (filename,suffix);}

Ifstream infile;
Infile.open (filename);
Ofstream out ("Copyfile.txt");
if (!infile)
{
cout<< "ERROR: Specified file not found" <<endl;
cout<< "Please copy the target file to the directory of this program" <<endl;
System ("PAUSE");//Systems Command screen paused
Exit (1); Exit
}
cout<< "The file is being read, please ..." later. <<endl;

while (!infile.eof ())
{
Getline (infile,s);
M=s.empty (); To determine whether a blank line
if (m!=true)
A.push_back (s);//If it is not a blank line, add this line of characters to the end of the vector
}

for (int i=0;i<a.size (); i++)
{Out<<a[i]<<endl;} The characters in the output vector to the new file

if (!out)
{
cout<< "Error,please Retry" <<endl;
Exit (2);
}

Infile.close ()//close file
cout<< "Congratulations, all blank rows were deleted successfully. "<<endl;
return 0;

}

hehe finally on the net a search, in fact this problem word has the solution .... That sweat.

But then again, this is purely for learning ....

The procedure also has the inadequacy, hope everybody is generous to enlighten ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.