日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux中win文件转为unix,如何将文本文件从Windows转换为Unix

發布時間:2023/12/9 linux 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux中win文件转为unix,如何将文本文件从Windows转换为Unix 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

從Unix轉換到Windows時,我得到正確的輸出;但是,從Windows到Unix時,我得到了一些奇怪的輸出。我認為我必須允許的是刪除回車'\ r'。雖然這不起作用。當我運行代碼后打開文本文件時,我得到了一些奇怪的結果,第一行是正確的,然后所有的地獄破壞。

int main( )

{

bool windows = false;

char source[256];

char destination[256]; // Allocate the max amount of space for the filenames.

cout << "Please enter the name of the source file: ";

cin >> source;

ifstream fin( source, ios::binary );

if ( !fin ) // Check to make sure the source file exists.

{

cerr << "File " << source << " not found!";

getch();

return 1;

}//endif

cout << "Please enter the name of the destination file: ";

cin >> destination;

ifstream fest( destination );

if ( fest ) // Check to see if the destination file already exists.

{

cout << "The file " << destination << " already exists!" << endl;

cout << "If you would like to truncate the data, please enter 'Y', "

<< "otherwise enter 'N' to quit: ";

char answer = char( getch() );

if ( answer == 'n' || answer == 'N' )

{

return 1;

}//endif

}//endif

clrscr(); // Clear screen for neatness.

ofstream fout( destination, ios::binary );

if ( !fout.good() ) // Check to see if the destination file can be edited.

{

cout << destination << "could not be opened!" << endl;

getch();

return 1;

}//endif

// Open the destination file in binary mode.

fout.open( destination, ios::binary );

char ch = fin.get(); // Set ch to the first char in the source file.

while ( !fin.eof() )

{

if ( ch == '\x0D' ) // If ch is a carriage return, then the source file

{ // must be in a windows format.

windows = true;

}//endif

if ( windows == true )

{

ch = fin.get(); // Advance ch, so that at the bottom of the loop, the

}//endif // carriage return is not coppied into the new file.

if ( windows == false )

{

if ( ch == '\x0A' ) // If the file is in the Unix format..

{

fout.put( '\x0D' ); // When a new line is found, output a carriage

}//endif // return.

}//endif

fout.put( ch );

ch = fin.get();

}//endwh

if ( windows == true )

{

fout.put( '\x0A' );

}//endif

fout.close();

fin.close(); // Close yer files.

if ( windows == true ) // A little output for user-friendly-ness.

{

cout << "The contents of " << source << " have been coppied to "

<< destination << " and converted to Unix format." << endl;

}else{

cout << "The contents of " << source << " have been coppied to "

<< destination << " and converted to Windows format." << endl;

}//endif

cout << "Enter any key to quit.." << endl;

getch();

return 0;

}//endmn

總結

以上是生活随笔為你收集整理的linux中win文件转为unix,如何将文本文件从Windows转换为Unix的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。