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 ...