Untitled

 avatar
unknown
c_cpp
a year ago
617 B
3
Indexable
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const string filename = "foo.txt";
const int n = 5;
void asd(const string& filename, int* num, int n)
{
	ifstream file(filename);
	if (!file.is_open())
	{
		cout << "ERROR" << endl;
		return 0;
	}
	int N;
	file >> N;
	if (N != n)
	{
		cout << "ERROR: ne sovpadaet kol-vo chisel i strok)";
		return 0;
	}
	for (int i = 0; i < N; i++)
	{
		file >> num[i];
	}
	file.close();
}
int main()
{	int num[n];
	asd(filename, num, n);
	for (int i = 0; i < n; i++)
	{
		cout << num[i] << " " << endl;
		return 0;
	}
}
Editor is loading...
Leave a Comment