• cmd控制台遍历目录文件名批量写入TXT


    其中.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;
    }
    
    
  • 相关阅读:
    MvvmLight:Command
    TreeView控件
    visual studio背景色
    公共语言运行时
    颜色列表
    自定义控件【旋转按钮,带圆角的边框】
    Loding Animation
    ComboBox前台xaml绑定数据
    Blend一些属性图解
    找到视觉树的方法
  • 原文地址:https://www.cnblogs.com/MorganMa/p/13958783.html
Copyright © 2020-2023  润新知