Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从文本文件中读取特定条目_C++_Text_Line_Fstream - Fatal编程技术网

C++ 从文本文件中读取特定条目

C++ 从文本文件中读取特定条目,c++,text,line,fstream,C++,Text,Line,Fstream,这是名为“TextFile.txt”的文本文件 这里是我的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>

这是名为“TextFile.txt”的文本文件

这里是我的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;
}
#包括
#包括
使用名称空间std;
煤焦站[9];
煤焦降雨量[9];
int i;
int j;
int s[23];
双r[23];
main()
{
ifstream读取;
Read.open(“TextFile.txt”);
读>>站;//我不想要这个
阅读>>降雨;//我别无选择,我只分配这两个变量
i=0;
而(!Read.eof())//这是我唯一想要的
{
i++;
阅读>>s[i]>>r[i];
}
Read.close();
对于(j=1;j使用
getLine()
阅读第一行,然后开始阅读第二行。我认为这是最可能的选择

你可以做这样的事情

ifstream stream("TextFile.txt");
string dummyLine;
getline( stream, dummyLine );
/*    
   Here you can read your values 
*/
while (stream)

可能这对你有帮助!!@baibhavk-Hmmm,这不是我的愿望。在我的文本文件中,前两个条目是标题。我想跳过它们,只读取数据。你是说从第一行开始读取吗?第一行是从一开始就提到的标题。我想跳过它,只读取标题下面的数据。我理解你的意思st使用getline()读取第一行,然后您可以读取实际数据,也可以逐行读取。不要使用eof()。
ifstream stream("TextFile.txt");
string dummyLine;
getline( stream, dummyLine );
/*    
   Here you can read your values 
*/
while (stream)