C++换行与读入

#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main( ){
    char c;
    freopen("1.txt","r",stdin);
    while((c=getchar())!=EOF){
        if(c=='\n')continue;
        cout<<c;
    }
    cout << "this is the first line\n";
    cout << "this is the second line\r";
    cout << "this is the third line\n";
    cout << "this is the fouth line\r";
    cout << "this is the fifth line\n";
    cout << "end";
	return 0;
}
/*文件
abc abc abc
bcde bcde bcde
   kkk
*/
/*输出
abc abc abc bcde bcde bcde    kkkthis is the first line
this is the third linee
this is the fifth line
end
Process returned 0 (0x0)   execution time : 0.635 s
Press any key to continue.
*/

事实证明,编程时换行就是用'\n',根本没有\r\n的事

猜你喜欢

转载自blog.csdn.net/cj1064789374/article/details/88954025