Splitting characters and int from a character array

This the file containing data:

R: 10
Steve Abrew 90 80 84 76
David Nag 93 87 90 80
Mike Black
Andrew Van Den 90 88 95 85
Chris Smith 86 74 90
Dennis Dudley 74 76 77 83
Leo Rice 95 75
Fred Flinstone 73 67 78 72
Dave Light 89 71 91 89
Hua Tran Du 81 79 80


I want to get the characters in a string variable and integers integer array.

Here is my code:

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main(int argc,char*argv[])
{


int array_size = 1024;

char * array = new char[array_size];

int position = 0;


ifstream fin(argv[1]);

if(fin.is_open())

{

cout << "File Opened successfully!!!. Reading data from file into array<<endl;



while(!fin.eof() && position < array_size)

{

fin.get(array[position]);

position++;

}

array[position-1] = '\0';


cout << "Displaying Array..." << endl << endl;

for(int i = 0; array[i] != '\0'; i++)

{

cout << array[i];

}

}

else

{

cout << "File could not be opened." << endl;

}


return 0;
}

But here i see the output is ok but everything is stored into a character array. But how can i store the characters in a string variable and integers integer array?
Topic archived. No new replies allowed.