reading input through .csv file (file wont open)

Hey guys,

I'm relatively new to C++ in some aspects but I know this is simple.
I'm writing a test case to add to another CUDA C program later to read in the input through .csv files and save them into an array (an attempt to mimic excel)

However the file will not open, but I'm not sure why. I have the file in the correct spot (same folder as .exe) yet it never opens. Do I have a problem with my code? Any help would be greatly appreciated.

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 
#pragma once
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string>							
#include <math.h>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>


using namespace std;

#define col		10
#define row		7

ifstream Isomer1;
ifstream Isomer2 ("Isomer2.csv");
ifstream SP ("SP.csv");
ifstream shift ("shift.csv");

string value;
double ioTemp;

double Isomer1_arr[row][col];
double Isomer2_arr[row][col];
double sp_arr[row][col];
double shift_arr[row][col];



void main(){

	Isomer1.open("isomer1.txt", ifstream::in);
	//input isomer 1 file into isomer1_array
	if (Isomer1.is_open())
  {

		while (Isomer1.good()){
			for(int j = 0; j < col; j++){
				for(int i = 0; i < row; i++){
					getline(Isomer1, value, ',');

					//check for end of row
					if(value.compare("~")){
						i = row;
					}

					//check for end of column
					if(value.compare("&")){
						j = col;
					}

					else
						ioTemp = strtod(value.c_str(), NULL); 
						Isomer1_arr[i][j] = ioTemp;

				}
			}

		}
			for(int j = 0; j < col; j++){
				for(int i = 0; i < row; i++){
					cout << Isomer1_arr[i][j] << "\t";
				}
		}
		Isomer1.close();
	}
	else cout << "Cannot open file." << endl;

	
	cout << endl << "\n Press any button to exit...";
	getch();
}
Knowing the error number would help.

change

else cout << "Cannot open file." << endl;

to

else cout << "Cannot open file. Err = " << errno << endl;
oh yeah haha oops.

It's exiting with error 2.

That's "cannot find file" But I have the isomer1.txt file in the same directory as the .exe file.

Do I have to setup a path for it? I thought it just looks in the directory of the .exe?
Last edited on
Any suggestions?

I haven't been able to get this working still.
Topic archived. No new replies allowed.