Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
617 B
0
Indexable
Never
#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;
	}
}
Leave a Comment