I need help removing the comma and some help with managing a "word"

Let's suppose that this is an another .txt file;
 
max,6,13.6,84.9,10.1,47.4


And this is what I write for the file input.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
	char name[200]={'\0'};
	int num[100]={0};
	float arr1[100]={0};
	float arr2[100]={0};;
	float arr3[100]={0};
	float arr4[100]={0};
	int count=0;
	
	ifstream file;
	file.open("test.txt");
	
	while(!(file.eof()))
	{
		file >> name[count];
		file >> arr1[count];
		file >> arr2[count];
		file >> arr3[count];
		file >> arr4[count];
		
		count++;
	}
}


I know in the name array only the alphabet "M" will go. How can I input the entire name or ignore it?

And after the data is read, this should be the output on the command prompt;
 
max 6 13.6 84.9 10.1 47.4

or
 
6 13.6 84.9 10.1 47.4


How can I do this?
Line 19: remove the [count]. e.g.
 
file >> name;


Do not loop on !eof(). This does not work the way you expect. The eof bit is set true only after you make a read attempt on the file. This means after you read the last record of the file, eof is still false. Your attempt to read past the last record sets eof, but you're not checking it there. You proceed as if you had read a good record. This will result in reading an extra (bad) record. The correct way to deal with this is to put the >> operation as the condition in the while statement.
1
2
3
  while (cin >> var) 
  {  //  Good cin operation
  }



while(cin >> var)
Whats var? I know its a variable. And how can i remove the comma?
That was just an example of how to correctly test for input failure instead of using !eof().
<var> was just an example variable.

The text I posted regarding !eof() was boilerplate since I see that error being made so often.
Last edited on
Topic archived. No new replies allowed.