读取并显示文件,但输出不正确
Reading and displaying a file but output is incorrect
我有这个文件:
###BEGIN
Player
FName: Jens
LName: Hogh
Club: Aalborg
Player
FName: Sebastian
LName: Perez
Club: Monaco
###COMPLETE
我必须读取并显示它。这是我到目前为止的代码:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string txt[300];
int i=0;
ifstream file ("example.txt");
std::string line;
while (std:: getline (file, line))
{
std:: cout << line; /* use `line' inside the while-loop. */
}
return 0;
}
输出错误!它显示如下:
BEGINPlayerFName: JensLName: HoghClub: alborgplayerfname: SebastianLName: PerezClub: Monaco###COMPLETE
都压在一起了。我如何得到它被分开,看起来像上面的文件?
std::cout << line;
你从不告诉程序打印换行符试试std::cout << line << 'n';
你也在你的文件开头指定using namespace std;
,这意味着你不需要把std::
之前的内置功能了。所以std::cout
可以写成cout
相关文章:
- Windows 10命令提示符的输出不正确
- C++ - 为什么 unicode 输出不正确?
- 我的叉子输出不正确
- C++使用 CEIL 和长度输出不正确的值
- 使用 iconv 进行 UTF8 转换的输出不正确
- C strftime()输出不正确
- 当行数和列不匹配时,输出不正确
- C++ 嵌套循环输出不正确
- 矩阵和矢量乘法,输出不正确的产品
- 我对这个问题有问题,我的输出不正确
- 上一个较大的数字代码中的输出不正确
- 二进制搜索树的输出不正确
- 拆解输出不正确(BeaEngine)
- 最大输出不正确
- 基本合并排序中的输出不正确
- 更改声明顺序时输出不正确
- Base64 转换器的输出不正确
- 使用 find_first_of() 和 substr() 分隔字符串,但我得到的输出不正确
- 对字符串进行索引时输出不正确
- .wav C++数据输出不正确