[英]Read Specific Entry From Text File
這是名為“ TextFile.txt”的文本文件。
Stat Rain
1 16
2 34
3 24
4 23
5 21
6 19
7 17
8 35
9 27
這是我的C ++代碼:
#include<iostream>
#include<fstream>
using namespace std;
char Station[9];
char Rainfall[9];
int i;
int j;
int s[23];
double r[23];
main()
{
ifstream Read;
Read.open("TextFile.txt");
Read>>Station;//I don't want this
Read>>Rainfall;//I have no choice then I just assign these two variables
i=0;
while(!Read.eof())//This is the only I want
{
i++;
Read>>s[i]>>r[i];
}
Read.close();
for(j=1;j<i;j++)
{
cout<<s[j]<<"\t"<<r[j]<<endl;
}
return 0;
}
我只想要數據。 那么,如何跳過第一行並立即閱讀第二行? 如果可能的話,如何在不浪費時間閱讀第一欄的情況下僅讀取第二欄?
使用getLine()
讀取第一行,然后開始讀取第二行..我認為這是最可能的選擇。
你可以做這樣的事情;
ifstream stream("TextFile.txt");
string dummyLine;
getline( stream, dummyLine );
/*
Here you can read your values
*/
while (stream)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.