python, c/c++去掉文本的换行符

1 需要分析

把上面的摘要复制到word里面会成这样;

C++实现

#include <string> 
#include <fstream> 
#include <iostream> 

using namespace std;

int main()
{
	ifstream myfile("input.txt");
	ofstream outfile("output.txt");
	string temp;
	if (!myfile.is_open())
	{
		cout << "Some errors" << endl;
	}
	while (getline(myfile, temp))
	{
		outfile << temp;
	}

	myfile.close();
	outfile.close();
	return 0;
}

input.txt

Remote collaboration on physical tasks is an emerging use of video telephony. Recent work suggests
that conveying gaze information measured using an eye tracker between collaboration partners could
be beneficial in this context. However, studies that compare gaze to other pointing mechanisms, such
as a mouse-controlled pointer, in video-based collaboration, have not been available. We conducted a
controlled user study to compare the two remote gesturing mechanisms (mouse, gaze) to video only
(none) in a situation where a remote expert saw video of the desktop of a worker where his/her
mouse or gaze pointer was projected. We also investigated the effect of distraction of the remote
expert on the collaborative process and whether the effect depends on the pointing device. Our result
suggests that mouse and gaze pointers lead to faster task performance and improved perception of
the collaboration, in comparison to having no pointer at all. The mouse outperformed the gaze when
the task required conveying procedural instructions. In addition, using gaze for remote gesturing
required increased verbal effort for communicating both referential and procedural messages.

君不见,黄河之水天上来,奔流到海不复回。
君不见,高堂明镜悲白发,朝如青丝暮成雪。

人生得意须尽欢,莫使金樽空对月。
天生我材必有用,千金散尽还复来。

烹羊宰牛且为乐,会须一饮三百杯。
岑夫子,丹丘生,将进酒,杯莫停。
与君歌一曲,请君为我倾耳听。

钟鼓馔玉不足贵,但愿长醉不复醒。
古来圣贤皆寂寞,惟有饮者留其名。
陈王昔时宴平乐,斗酒十千恣欢谑。
主人何为言少钱,径须沽取对君酌。
五花马,千金裘,呼儿将出换美酒,与尔同销万古愁。


Python实现

#  coding:utf-8
import codecs

newlines = []
fileOpen = codecs.open("ReadMe.txt", "r", "UTF-8")  # 打开以utf-8格式
fileSave = codecs.open("input.txt", "w", "UTF-8")  # 保存utf-8格式
for line in fileOpen.readlines():
    line = line.strip()
    fileSave.write(line + " ")
fileSave.close()

猜你喜欢

转载自blog.csdn.net/moonlightpeng/article/details/91885403
今日推荐