C++常用小工具……

1. 批量改变文件内容:

//批量改变输出文件内容

#include <fstream>

#include <iostream>

#include <string>



using namespace std;



int main(){

    ifstream input("D:pos_img.txt");

    ofstream output("D:pos_image_o.txt");

    string strin,strout;

    while(input>>strin){

        strout ="pos_image/"+strin;

        strout+=" 1 0 0 40 40";

        output<<strout<<endl;

    }

    return 0;

}

效果如图:

      改前                                    改后

C++常用小工具……C++常用小工具……

 

2 .利用TinyXML把.xml转化为.txt,以便日后离线处理。

#include "tinystr.h"

#include "tinyxml.h"

#include "concrt.h"

#include <fstream>



#include <iostream>

#include <string>



using namespace std;



ofstream output("D:ImageInfo.txt");



bool ReadXmlFile(string& szFileName){

    TiXmlDocument *myDocument = new TiXmlDocument(szFileName.c_str());

    if(!myDocument->LoadFile())

        return false;



    TiXmlElement *RootElement = myDocument->RootElement();

    TiXmlElement *ItemsElement = RootElement->FirstChildElement()->NextSiblingElement();



    TiXmlElement *ItemElement = ItemsElement->FirstChildElement();

    for(;ItemElement!=NULL;ItemElement=ItemElement->NextSiblingElement())

    {//Item循环

        TiXmlAttribute *ItemAttribute = ItemElement->FirstAttribute();

        output<<ItemAttribute->Value()<<endl;



        TiXmlElement *LabelElement = ItemElement->FirstChildElement();

        for(;LabelElement!=NULL;LabelElement=LabelElement->NextSiblingElement())

        {//子元素Label循环

            TiXmlAttribute *labelAttribute = LabelElement->FirstAttribute()->Next();

            for(;labelAttribute!=NULL;labelAttribute=labelAttribute->Next())// Label属性循环

                output<<labelAttribute->Value()<<endl;

            //Concurrency::wait(1000);//输出到控制台的时间控制

        }

        output<<endl;

    }

    cout<<"complete";

    return 1;

}



int main(){

    string fileName = "D:dongnanmeneast_15_1920x1080_30_R1.xml";

    //CreateXmlFile(fileName);

    ReadXmlFile(fileName);

}

TinyXML源文件+main()+dongnanmeneast_15_1920x1080_30_R1.xml+ImageInfo.txt 下载地址

3. 获取系统当前时间:

#include <windows.h>

#include <iostream>

using namespace std;



int main()

{

    SYSTEMTIME sys;

    GetLocalTime( &sys );

    cout<<sys.wYear<<sys.wMonth<<sys.wDay<<"_"<<sys.wHour<<sys.wMinute<<sys.wSecond<<endl;

    return 0;

}

多么美好的一天,又这么无聊的度过了。Learning efficiency is too low. Come on...beenking

 

你可能感兴趣的:(C++)