其中.lib為文件名后綴,0.txt為寫入文件
dir /b *.lib >0.txt
附0.txt分離代碼,可將奇數行和偶數行分離,僅供參考
#include <iostream>
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream txtfile;//打開讀取的文件
ofstream txt01;//保存的文件
ofstream txt02;//保存的文件
string temp;
int index = 0;//用於判斷奇偶
txtfile.open("0.txt", ios::in);
while (!txtfile.eof()) // 若未到文件結束一直循環
{
getline(txtfile, temp);//一行一行讀取
if (index % 2 == 0)//判斷除以2的余數,即為奇偶的判斷
{
txt01.open("1.txt", ios::app);
txt01 << temp;
txt01 << endl;
txt01.close();
}
else
{
txt02.open("2.txt", ios::app);
txt02 << temp;
txt02 << endl;
txt02.close();
}
index++;
}
txtfile.close(); //關閉文件
txtfile.close();
txt01.close();
txt02.close();
return 0;
}