I make a program that reads a file and then it stores the information in two char.The problem is related to the char Elements and symbol. What is causing errors in my program? Thanks in advance.
#include "stdafx.h"
#include <iostream>
#include <fstream>
char* Elements;//The problem
char * symbol;
using namespace std;
bool read(char* Filename){
int maxlines;
ifstream file;
file.open(Filename);
if(!file) return false;
while(file.eof()){
file >> maxlines;
Elements = new char[maxlines];
symbol = new char[maxlines];
for(int i = 0; i < maxlines; i++)
{
file >> Elements[i] >> symbol[i];
}
}
return true;
}
int main(){
read("Periodic Table.txt");
cout << Elements[2] << endl;
system("pause");
return 0;
}