Windows与Linux代码移植 -- dos2unix与unix2dos - graybull's Blog
Windows与Linux代码移植 -- dos2unix与unix2dos
graybull
posted @ 2013年2月24日 19:52
in Unix/Linux
with tags
linux dos2unix windows c++ unix2dos
, 4732 阅读
- dos2unix和unix2dos
- 安装dos2unix和unix2dos
- 某些代码运行错误例子
dos2unix和unix2dos
Windows和Linux下文本文件的行结束标志不同。windows中以“\r\n”表示回车换行,而Linux中以“\n”表示回车换行。
dos2unix将“\r\n”转换成“\n”。
unix2dos将“\n”转换成“\r\n”。
使用方法:
dos2unix <filename>
安装dos2unix和unix2dos
#查看
$yum list | grep dos2unix
#安装,类似于:
$sudo yum install dos2unix.x86_64
某些代码运行错误例子
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr
某一次,我从Windows移植C++代码到Linux,编译链接后,运行可执行文件,出现了以上错误。
一般地,该异常是指使用标准库函数substr()时,超界了。
然而,这份代码在windows下是正常的,没有超界问题。证明逻辑是木有问题的。
于是,我试着用dos2unix转换了程序读取的文本文件和C++代码文件。问题就没了!
2019年8月03日 05:36
I hope I could find more updates from you, thank you for sharing hotmail email login
2019年10月12日 01:04
Most people and a person had welcomed the newborn prohibited. Now if your kids grow you can don’t have enough time towards spare for the purpose of sitting along with them everyday. It is just about the right enough time to hire some babysitter to enjoy serenity. Perhaps you could be deterred to employ Babysitter through Dubai reside have been aware of a considerable amount of thrilling content about irresponsible teen years who only took care the youngsters.