Read all values from CSV (0's included)

Like it says in the title bar, I want to know if the numbers being loaded into the array are all being saved including the 0's. The file will load something like this
1
2
3
0, 0000,
1, 0001,
etc.

Does the following code take in the zeros that would be above?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void binary_file(){

	string val;
	double num ;
	ifstream myfile;
	myfile.open("Binary.csv");
	if(myfile.is_open()){
		while(!myfile.eof()){
			
			for(int i = 0; i < 16; i++){
				for(int j = 0; j < 2; j++){
			
					getline(myfile,val,','); 
					num = atoi(val.c_str());
					binary_nums[i][j] = num;
				}
			}
		}
	}
	
}


I am using printf("%d ",binary_nums[i]) to see the contents of the array, and that might be my issue. Is there another way to view the numbers? Tried the c++ forum. Are the zeros actually being put into the array?
atoi will convert "0001" to [1] and "0000" to just [0].

not sure if i am understanding you correctly
That is what I was wondering. Was unsure how the atoi worked. Have you got any other ideas as to how to get the numbers out? I could work with a string I guess, but it would be best if I could deal with the numbers.
why are the leading zero's in [0001] important to your solution?

how do you intend to use these fields?

would [0001] and [001] be the same or would they be viewed in your solution as two different things.

If they will be two different things, then it would seem as if you should be using this field as a string and not as an integer.

If however you should be using these fields as numbers and later need to print them with the leading zeros preserved then you could try something like:

1
2
3
4
5
int fld = atoi("0001");

...

printf("%04d", fld);
Need the leading bits. Creating a simulated caching system for a processor. Have found that if I use fscanf and take nums in as hex that way it might work with a different approach. Thanks for the help.
you can always use stringstream and then put the value in the integer variable . but , 000 will be 0 and 001 will be 1 .
Topic archived. No new replies allowed.