简体   繁体   中英

Reading integers from a text file

I have a text file, in which I am writing 3 things

Eg < int,int,char> for each word.

Now, I am reading the file such that I consider a block of 3.1st one I always consider an integer, 2nd one also as integer and the 3rd one as character .There is no problem when the integer is from 0-9 but when it exceeds like 10,100 then my program doesn't work for the obvious reasons.

Like there is no problem when I have to read this

11a     here <1=int,1=int,a=char>

but when something like this comes, I face problem

152a    here <15=int,2=int,a=char>

I have put the whole text file in a string.Now, how how do I read the characters that I no longer face the above mentioned problem

Some more info: My text file contains characters like this
11a22d33f1234f

Given your current description of the problem, there is no way to determine if an entry such as

152a

corresponds to (15,2,a) or (1,52,a) .

Why don't you write to the file with some delimiter between elements, and then split() around the delimiter when reading back in from the file?

您的文本文件格式不正确,那么您想如何区分“ 1 11 a”和“ 11 1 a”?例如,您不能使用csv或类似的东西吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM