我完全不知道自己是什麼會做這個ifstream的獲得()不填充字符數組
#include "fstream"
#include "iostream"
using namespace std;
#define out(a) cout << #a << ": " << a << '\n'
void print(string s)
{
cout << s << '\n';
}
int main()
{
ifstream readt1;
readt1.open("test1.yaml");
while(readt1.good())
{
char cc[128];
readt1.get(cc,128);
out(cc);
}
readt1.close();
}
代碼...輸出這樣的:
cc: version: 0.14.1
cc:
與test.yaml感這
version: 0.14.1
name: scrumbleship
author: dirkson
description: >
A minecraft like game that allows you
to build your own spaceship!
我試了很多方法來得到這個工作,而且它根本不
哦,我的上帝,當我需要它的時候,這到底是什麼地方?你在哪裏找到它?我會盡快接受(等待5分鐘) – alexmherrmann
當您執行'readt1.get(cc,128);'它會提取127個字符或者直到換行符(即'\ n'),下次您嘗試讀取它失敗的內容,因爲您沒有忽略換行符。 –
因此,忽略就像跳過它,但仍增加gcount? – alexmherrmann