I am having a problem with my code. I am writing a program to read an input from a file(just 50 lines of three digits numbers each) and then put it into a 2 dim array where a row is going to be a whole number where colums are going to be the numbers in 1st, 2nd and 3rd position (it is for Project Euler)
I succeed in reading the inputs from a file. But then when i try to convert the numbers in a string in doesnt work because it gives me the invalid conversion error.
The code is:
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
fstream myfile ("keylog.txt");
string tries[60];
string line;
char codes[50][3];
int i = 0;
int j = 0;
int code[50][3];
while(myfile.good()){
getline(myfile, line);
tries[i] = line;
i++;}
for(i = 0; i < 50; i++){
for(j = 0; j < 3; j++){
code[i][j] = atoi( tries[i][j] );
}
}
return 0;
}
It compiles with the following error
keylog.cpp: In function ‘int main()’:
keylog.cpp:24:35: error: invalid conversion from ‘char’ to ‘const char*’
keylog.cpp:24:35: error: initializing argument 1 of ‘int atoi(const char*)’
I have been playing with this couple of hours but I could not figure out what it is.
Any help would be appreciated.
Best regards
Mike