- #include <sys/time.h>
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <string.h>
- using namespace std;
- void usage()
- {
- cout << "Please input like this:" << endl;
- cout << "WinToLinux oldfile newfile" << endl;
- }
- int main(int argc, char **argv)
- {
- unsigned int timeuse;
- struct timeval stStartTime;
- struct timeval stEndTime;
- usage();
- gettimeofday(&stStartTime, NULL);
- if(argc != 3)
- {
- cout << "Parameter is not deserved!" << endl;
- return -1;
- }
- ifstream fin(argv[1]);
- ofstream fout(argv[2]);
- if(!fin.is_open())
- {
- cout << "Open file failed,please check your file path." << endl;
- }
- string strTmp;
- while(getline(fin, strTmp))
- {
- if(strTmp[strTmp.size() -1 ] == '\\r')
- {
- strTmp.erase(strTmp.size() - 1, 1);
- }
- fout << strTmp << endl;
- strTmp.clear();
- }
- gettimeofday(&stEndTime, NULL);
- timeuse = 1000000*(stEndTime.tv_sec - stStartTime.tv_sec) +
- stEndTime.tv_usec - stStartTime.tv_usec;
- cout << "Use time : " << timeuse/1000000.0 << " sec" << endl;
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/2101201511590.html
来源: http://www.codesnippet.cn/detail/2101201511590.html