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.mzph.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;按照我…