Ask coding questions

← Back to all posts
Adding certain parts of a text file into an array
JustinWu (8)

I know one way how to do textfile insertions are while(infile >> character >> integer >> integer2), but what should I do if I wanted to create a character variable and an array of integers out of a single text file line?

Comments
hotnewtop
DynamicSquid (5029)

The best you can do is this:

char c;
file >> c;

int arr[10];
for (int i = 0; i < 10; ++i)
  file >> arr[i];
JustinWu (8)

@DynamicSquid
I was testing that today and I think a possible better way than that is to get a string of characters parsed and put through a function which returns values relative to the input.