- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
基本上,我试图将相同的信息流式传输到一个文本文件中,并将相同的信息流式传输到另一个文本文件中。
但是,它给了我奇怪的新行。
要测试的示例 txt:
testing this is a test to see if this actually works
hopefully!
test
test
test
这是它在测试后给我的输出:
testing this is a test to see if this actually works
hopefully!test
test
test
我希望输出与输入相同。但我不确定我做错了什么。已经坚持了几个小时了,哈哈。
这是我的代码:
string input, name, content;
cout << "Enter input name and extension (Example: hi.txt)\n";
cin >> input;
ifstream file (input.c_str());
if (file.is_open()) {
cout << "Enter output name and extension (Example: hi2.txt)\n";
cin >> name;
ofstream output(name.c_str());
while (getline(file, content)) {
output << content;
if (content == "") {
output << "\n";
}
}
}
最佳答案
std::getline
忽略分隔符,在读取一行时默认为 \n
。所以,当它读到
testing this is a test to see if this actually works\n
content
实际上是
testing this is a test to see if this actually works
注意缺少的换行符。这就是为什么每一行之后都少了一个新行 :)
您必须添加被丢弃的定界符:
output << content << '\n'; //Adds the discarded '\n' delimiter
关于c++ - 在 C++ 中流入和流出文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38862584/
首先是我的 table : mysql> desc invoice; +-------------+-----------------------+------+-----+---------+---
我有一些这样的 HTML: 和 CSS div#container { width:960px; margin:0 auto; } div#main {
我有这个列表: myList = [a, a, a, b, b, a, c, c, b, a] 我想计算每个唯一项目的流入和流出。 “a”的流入 = 出现次数 = 5(当转换进入“a”时) 'a' 的
我制作的布局需要在移动屏幕上可见。目前,当我缩小到移动设备或在我的 iPhone 5 上查看网站时,其中带有较长文本的 div 到处都是。 由于我将所有内容都包装在称为 section0、sectio
所以我在这里遇到了一个问题,考虑到我正在创建一个简单的导航栏,这个问题特别令人沮丧。我到处寻找解决方案都无济于事,所以希望你们能对此有所启发。发生的事情是,我所有的标签都没有显示在导航栏内,它实际上是
如果我在输入字段中单击,填充应该变为零,以便边框紧挨着文本。问题是它保持宽度并因此流出 div 父级;[ div { width: 400px; background-colo
我有一个 UIImage(尺寸 320x480),我想用更小的 UIImageView(尺寸:100x100)显示。 但是当我添加图像时,它会渗透到 UIImageView 及其父 View 中。如何
我们正在尝试将我们的 zip 微服务从 nodejs Express 中的常规应用程序迁移到与 AWS Lambda 集成的 AWS API Gateway。 我们当前的应用程序向我们的 API 发送
我遇到了一个非常奇怪的问题,经过多次尝试和研究我无法摆脱它。我有一个网站,但是一些(只有 5% 的访问者)使用相同版本的 chrome 的人看到文本从 divs 流出并且文本重叠。这很奇怪,因为我使用
这只是我的代码片段。我似乎无法将图像锁定在 div 中,如果我设置 margin-top: 50% 它就会从 div 中流出。我该如何阻止它?我还想在包含它的 div 的死点设置图像。 var twi
我是一名优秀的程序员,十分优秀!