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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/394783.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/394783.shtml
英文地址,請注明出處:http://en.pswp.cn/news/394783.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

程序員偽造一年工作經驗_試火—如何偽造程序員

程序員偽造一年工作經驗2017年9月6日 (6 September 2017) Sweat is running down my face. I’m staring down a blank sublime text document. What on earth am I doing? My hands are resting above the keyboard of my MacBook pro.汗水順著我的臉。 我盯著一個空白的崇高…

在unity中設置多種怪物數據_Unity可編程渲染管線(SRP)系列(三)——光照(單通道 正向渲染)...

本文重點:1、漫反射著色2、支持方向光、點光源和聚光燈3、每幀允許16個可見光源4、每個對象最多計算四個像素光和四個頂點光這是涵蓋Unity可編寫腳本的渲染管線的教程系列的第三部分。這次&#xff0c;我們將通過一個Drawcall為每個對象最多著色8個燈光來增加對漫反射光照的支持…

Java內部類的定義和使用

為什么要用到內部類&#xff1a; 在java開發學習中我們經常會碰到內部類。內部類又有很多的優勢&#xff1a;首先舉一個簡單的例子&#xff0c;如果你想實現一個接口&#xff0c;但是這個接口中的一個方法和你構想的這個類中的一個方法名稱參數相同&#xff0c;你應該怎么辦&am…

蛋清打發奶油狀

在做蛋糕、冰淇凌、面包之類的時候往往都需要奶油狀蛋清&#xff0c;讓蛋糕、面包更蓬松&#xff0c;冰激凌也可以使用其當做奶油來用。用料 雞蛋4個 根據用量選擇鹽(只做冰激凌用奶油放)5g(根據蛋量)白醋(可以不放&#xff0c;根據喜好)5g(根據蛋量)白砂糖40g(分三次放)根據…

react構建_您應該了解的有關React的一切:開始構建所需的基礎知識

react構建by Scott Domes由斯科特多姆斯(Scott Domes) 您應該了解的有關React的一切&#xff1a;開始構建所需的基礎知識 (Everything You Should Know About React: The Basics You Need to Start Building) Are you curious about React and haven’t had the chance to lea…

榮新linux培訓,51CTO博客-專業IT技術博客創作平臺-技術成就夢想

切換用戶 su - root文件夾管理 mkdir(新建文件夾) rmdir(刪除空目錄)文件管理 touch(新建文件) rm(刪除文件)rm -rf(刪除文件夾) cat(查詢文件)文件文件夾 mv(剪切文件) cp(復制文件)默認拷貝文件&#xff0c;cp -r 就可以拷貝文件夾啦批量建文件 touch /root/tes…

Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays

題目鏈接 題意&#xff1a;給你兩個數x,yx,yx,y,讓你構造一些長為yyy的數列&#xff0c;讓這個數列的累乘為xxx&#xff0c;輸出方案數。 思路:考慮對xxx進行質因數分解&#xff0c;設某個質因子PiP_iPi?的的冪為kkk,則這個質因子的貢獻就相當于把kkk個PiP_iPi?放到yyy個盒子…

《面向對象分析與設計》一第2章 什么是面向對象分析

第2章 什么是面向對象分析 面向對象分析&#xff08;ObjectOriented Analysis&#xff0c;OOA&#xff09;&#xff0c;就是運用面向對象方法進行系統分析。它是軟件生命周期的一個階段&#xff0c;具有一般分析方法所共同具有的內容、目標及策略。但是OOA強調運用面向對象方…

hql可以使用distinct嗎_輸送食品可以使用白色PVC輸送帶嗎?

食品&#xff0c;是給人們吃到肚子里的&#xff0c;因此不管在加工環節、制造環節還是其他環節&#xff0c;都需要做好食品的安全問題。根據不同的食品&#xff0c;其制造的環境也不同&#xff0c;所使用到的食品輸送帶的材質也是不一樣的&#xff0c;這些是需要根據輸送的食品…

htc one m7 linux驅動,HTC One M7官方RUU固件包(可救磚)

在網上找了找關于HTC One M7 (801e)的官方ruu固件包還不多&#xff0c;找了一些&#xff0c;不過有些不能下載&#xff0c;在這里整理了幾款可以下載的官方ruu包&#xff0c;這些包都是官方原版的&#xff0c;都是支持線刷的&#xff0c;大家可以下載下來備用了&#xff0c;也可…

emoji .png_根據我對3.5GB聊天記錄的分析,Emoji開發人員使用最多

emoji .pngby Evaristo Caraballo通過Evaristo Caraballo 根據我對3.5GB聊天記錄的分析&#xff0c;Emoji開發人員使用最多 (The Emoji developers use most — based on my analysis of 3.5GB of chat logs) Emoji have drastically changed the way we communicate in socia…

forward和redirect的區別

1.從地址欄顯示來說forward是服務器請求資源,服務器直接訪問目標地址的URL,把那個URL的響應內容讀取過來,然后把這些內容再發給瀏覽器.瀏覽器根本不知道服務器發送的內容從哪里來的,所以它的地址欄還是原來的地址.redirect是服務端根據邏輯,發送一個狀態碼,告訴瀏覽器重新去請求…

CF662C Binary Table(FWT)

[Luogu-CF662C] FWT_xor 題目描述 有一個 \(n\) 行 \(m\) 列的表格&#xff0c;每個元素都是 $0/1 $&#xff0c;每次操作可以選擇一行或一列&#xff0c;把 \(0/1\) 翻轉&#xff0c;即把 \(0\) 換為 \(1\) &#xff0c;把 \(1\) 換為 \(0\) 。請問經過若干次操作后&#xff0…

c語言fmin最小公倍數,matlab小函數

8種機械鍵盤軸體對比本人程序員&#xff0c;要買一個寫代碼的鍵盤&#xff0c;請問紅軸和茶軸怎么選&#xff1f;(記得按字母序索引)矩陣向量化操作A(:)拉成一個向量 ($a_{11},a_{21},…$)&#xff0c;注意先列后行repmat用途&#xff1a;創建由小型矩陣重復組合成的矩陣&#…

spring管理的類如何調用非spring管理的類

spring管理的類如何調用非spring管理的類. 就是使用一個spring提供的感知概念,在容器啟動的時候,注入上下文即可. 下面是一個工具類. 1 import org.springframework.beans.BeansException;2 import org.springframework.context.ApplicationContext;3 import org.springframewo…

django構建網頁_如何使用Django構建照片供稿

django構建網頁by Ogundipe Samuel由Ogundipe Samuel 如何使用Django構建照片供稿 (How to build a photo feed using Django) Today, we will make a real-time photo feed framework using Django and Pusher. This is like a mini Instagram, but without the comments and…

報表系統的雄心

這周有朋自遠方來&#xff0c;聊了對報表工具的看法&#xff0c;因此專門寫篇文章來談談報表系統的未來。 筆者知道不可能有十全十美的報表系統&#xff0c;畢竟任何一個行業和企業受自身客觀環境的限制&#xff0c;但表哥嘛&#xff0c;總要有點理想和追求&#xff0c;就好比到…

02----mockjs基本使用

一.mockjs基本使用 1.安裝mockjs cnpm install mockjs --save-dev2.新建mockjs文件夾/index.js // 引入 Mock var Mock require(mockjs)// 定義數據類型 var data Mock.mock({// 20條數據"data|20": [{// 商品種類"goodsClass": "女裝",// 商品…

vuefullcalendar怎么判斷切換上下月_房間太多、樓上樓下,終極解決家里wifi信號無縫切換問題...

相信不少人有我一樣的煩惱&#xff0c;房間太多&#xff0c;或者樓上樓下&#xff0c;家里的wifi信號總是不能無縫切換。路由器放在配電箱&#xff0c;除了客廳信號不錯外&#xff0c;一旦到了其他房間&#xff0c;掉線、網速慢等問題讓人很苦惱。特別是和小伙伴一起玩游戲一邊…

C語言程序順序結構1交換變量,如何將c語言中結構體內的所有類型變量的值輸出來...

教了多年《C程序設計》課程&#xff0c;大多學生覺的這門課程難學。其實&#xff0c;按照我們現在的教學大綱和教學要求&#xff0c;只要同學們掌握一些方法&#xff0c;克服心理上畏難、不輕言放棄&#xff0c;是完全可以學好的。《C 程序設計》的內容很豐富&#xff0c;按照我…