I need to read a txt file as data input. The format of the txt data is:
...
x x C
C
x x C
x x C
C
C
...
where x represent numeric value, C is charater, and the same format repeated many times, but may change to another format as follows:
x x C
C
x x C
C
C
x x C

Numeric value x has to be put in an array, say, int N; and character value will be put in a character array, CH. Can some one here give me a hint on how to make a C++ program to read this piece of data?

Thank you so much!

read each token from each line one at a time into a string. If the first char of the string is alphabetical, then it's a char and if not then it's numerical (assuming those are the only two options for stuff in the file). If it's numerical then convert it from string value to numerical value before entering the value into the array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.