Loading 2D Array From File w/ Double Pointer

Hi there. I've been trying for a while to nail down a loading function for my project. I have other manipulation functions which should work, but the sticking point for me is getting the data to import. I just don't have a complete understanding of it.

Basically, I want to assign a 2D array to my double pointer, of which I know the size (but I could choose to change the dimensions before testing). The file is comma delimited, and looks something like this:

123,211,144,55
44,100,0,111

etc.

Below is my implementation.

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
28
29
30
31
32
33
34
35
36
37
38
39
bool loadData(int **imgPix, string fileName) {
	
	ifstream inputFile;
	
	inputFile.open(fileName.c_str());
	
	string tempLineRow; //The resulting line from the text file
	string tempElementColumn; //The individual integer element 
	int numberOfCols = 0;
	int numberOfRows = 0;
		
		
	if (!inputFile.is_open()) {
		return false;
	}
	
		while (getline(inputFile, tempLineRow, '\n')) {
			
			stringstream ss; 
			ss << tempLineRow; //Stringstream version of the line
			
			while (getline(ss, tempElementColumn, ',' )) {
				stringstream ss2; 
				ss2 << tempElementColumn;
				ss2 >> numberOfCols;
				
				
				
				numberOfCols++;
		        
			}
			
			numberOfRows++;
			
		}	
		
	inputFile.close();
	return true;
}


I have a feeling I could be close, but I'm concerned about the actual assignment, which I have not included. I need to load each value in the array with one of the separate integers separated by commas.

Previously, I had a statement something like *(*(imgPix + numberOfRows) + numberOfCols) in the inner loop, but it didn't seem to work. I'm also not sure if the inner loop is the place for it to go, but given the location of my iterators, it seems likely.

Any help would be greatly appreciated in this final step! Thanks.
Topic archived. No new replies allowed.