-1

AT

4
5
6
7

#include<iostream>
#include<stdio.h>
#include <fstream>
using namespace std;

int main()
{
    int data[4], a, b, c, d, e, f;
    ifstream myfile;
    myfile.open("tera.txt");
    for (int i = 0; i < 4; i++)
    {
        myfile >> data[i];
    }
    myfile.close();
    a = data[0];
    b = data[1];
    c = data[2];
    d = data[3];
    cout << a << "\t" << b << "\t" << c << "\t" << d << "\n";
    return 0;
}

it takes AT also and give garbage value. how and where should i use ignore function to ignore AT Value. And there is one thing more if there is another array given BT containing some value like this: AT BT how to store BT's all values under it in an array?

Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74
Shani Mughal
  • 105
  • 13

1 Answers1

0

You just have to skip the first line. You can also add optional error handling, otherwise read may fail for all line.

if (!myfile)
{
    cout << "can't open\n";
    return 0;
}

string temp;
myfile >> temp;
cout << "first line: " << temp << endl;
for (int i = 0; i < 4; i++)
{
    myfile >> data[i];
    if (myfile.fail())
    {
        cout << "error\n";
        myfile.clear();
        myfile.ignore(1000000, '\n');
    }
}
Barmak Shemirani
  • 30,904
  • 6
  • 40
  • 77