Chinaunix首页 | 论坛 | 博客
  • 博客访问: 24783
  • 博文数量: 14
  • 博客积分: 1513
  • 博客等级: 上尉
  • 技术积分: 140
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-09 13:45
文章分类
文章存档

2012年(2)

2011年(7)

2010年(5)

最近访客

分类: LINUX

2010-11-29 22:03:17

 昨天写Java程序时(Linux下)写到:
 fin = new FileInputStream(FileDescriptor.in);
 fout = new FileOutputStream("out.txt");
 System.out.print("please input a string:");
 while((ch = fin.read()) != '\r')
      fout.write(ch);
 fin.close();
 fout.close();
 System.out.println("write success!");
 程序执行时输入无法结束,原以为是程序不对,问过学长后才知道,这种情况跟  运行平台有关。转义字符在不同的平台下有一点小差别,其中最常见的就是'\n''\r'.
 回车:将光标移到当前位置行首;
 换行:将光标移到当前位置下一行的行首;
 Unix/Linux系统里,每行行尾只有一个换行符'\n',Windows系统中每行行尾是回车换行即:'\r\n',而Mac系统中每行行尾是'\r'。最常见的Linux/Unix/Mac系统里的文章在Windows下会显示为一行,而Windows下的文章在Linux下打开每行行尾会多出一个^M.
 Linux中单独使用'\r',系统会将光标移到当前行首,并且将该行清空;如果将'\r'与'\n'搭配使用,系统会将'\r'与'\n'之间的字符依次插入到该行行首,同时将对应的原有字符覆盖;而'\r\n'就相当于'\n'.
 例如:
  #include
 
  int main(void)
  {
     printf("Hello World!\r Beautiful World!\n");
     printf("How are you!\rh\n");
     printf("Dog is an animal\r\n
What's your name?");
    
     return 0;
  }

  输出结果如下:
   Beautiful World!
  how are you!
  Dog is an animal
  What's your name?



阅读(948) | 评论(1) | 转发(0) |
0

上一篇:泛型小感

下一篇:关于内存对齐

给主人留下些什么吧!~~

chinaunix网友2010-12-03 00:47:46

加油!!!