D
D
danielsolosyatov2014-01-10 20:46:10
C++ / C#
danielsolosyatov, 2014-01-10 20:46:10

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

2 answer(s)
V
Vladimir, 2014-01-10
@noonv

of course :)

V
Vladimir Prikhodko, 2014-01-10
@cska63

#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;
}

PS Learn how to use Google. You have some stupid questions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question