I am trying to read a file with separate columns and including each word of a column in an array. Some of them are numeral, other literals. For the literals, I am always getting and error of type conversion. Any idea? Here follows the code:
#include <iostream>
#include <fstream>
#include <cmath>
int main ()
{
string line;
int a=100;
ifstream data;
data.open("filename.txt");
getline(data,line);
int number[a];
const char *at[3][a];
const char *rt[3][a];
int rn[a];
for (int j=0;j<a;j++)
{
number[j] = stoi(line.substr(6,6));
at[j] = line.substr(13,2);
rt[j] = line.substr(13,2);
rn[j] = stoi(line.substr(22,4));
getline(pdb,line);
}
return 0;
}
I appreciate any help!
substrreturns astd::string. You cannot assign that to an array of char pointers (or whatever those variables are supposed to be).std::stringandstd::vector?