Answer the question
In order to leave comments, you need to log in
Write from file to array before space C++?
There is a file with numbers separated by a space: 324 5676 424 43434. The program has an array a. It is necessary to write each number up to a space from the file into an array element a. Is it possible to do this?
Answer the question
In order to leave comments, you need to log in
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
string namefile = "file.txt";
ifstream ifs(namefile.c_str());
if (!ifs) cerr << "can't open file\n";
int a = 0;
while (ifs >> a)
cout << a << '\n';
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question