I am trying to open a ".txt" file and read the content from the first line and the content from the second line. There are some numbers separated with a simple "space" on both lines of the ".txt" file.
How can I read the content from the first line and save each number in x[100] and read the content from second line and save each number in y[100]?
PS: I am a beginner.
#include<iostream>
#include<fstream>
using namespace std;
int main() {
int x[100], y[100], i=0;
ifstream myfile("something.txt");
while(myfile >> x[i]) {
cout << x[i] << "\n";
i++;
}
return 0;
}
Thank you so much!
Aucun commentaire:
Enregistrer un commentaire