functions with ifstrem

is there a way to move the ifstream out of the main function and put into a separate function? any ideas on how to do it are welcomed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  //function to read the contacts.txt file
	ifstream infile1; //Contact.txt
	infile1.open("contacts.txt");

	if (infile1.is_open())
	{
		string temp;
		float  id, cw, cs, ce, dist; //place holders 
		
		

		getline(infile1, temp);

		while (infile1 >> id >> cw >> cs >> ce >> dist)
		{
			
			user_ids[size]= id;
			contact_with[size]=cw;
			contact_start[size]=cs;
			contact_end[size]=ce;
			distance[size]=dist;
			size++;
		
Yes. But it depends on what you're trying to achieve.

Can you provide some context to help us understand what you want?

EDIT: Please don't double post. https://www.cplusplus.com/forum/beginner/280699/
Last edited on
Topic archived. No new replies allowed.