Problems with storing and outputing data from a text file
Hi all...I really need someones help and real fast. I am trying to read a textfile with multiple columns that are each separated by a #. eg:
Inventory.txt
Nokia Lumia 610#Nokia#Touch#8GB#8#Tango OS#3899.00#
Blackberry Curve 9380#Blackberry#Both#1GB#8#Blackberry OS 7#3499.00#
Samsung Galaxy S3#Samsung#Touch#32GB#8#Andriod#6999.00#
iPhone 4S#Apple#Touch#16GB#8#IOS#7899.00#
I am trying to save each bit of data in separate variable in a structure because later on I am going to perform calulates and editing but for now. I cant seen to get it to work. When I run my code, it only displays the first line and nothing else. Plus it shows a weird number at the beginning: 1.13002e-317
Can someone help correct my code to display all of the textfile in neat columns and store each in its owm variable correctly.
ps: I cant help think I need to be using Pointers, can someone help with that too
Related Article:Reading Text file and storing characters in 2D Array
is a C++ discussion thread by Doogledude123 that has 5 replies, was last updated 4 months ago and has been tagged with the keywords: 2d, array, text, file, reading, storing, characters.
There is no information about cellphone[] in your entire program. One more thing read Click Here
The description for Delim says:
The operation of extracting successive characters is stopped when this character is read.
So if you do getline and pass '#' as delin, it will stop reading data after name.
I can suggest go for getLine but do not use delim, with return string you can always use strtok and get all the information using a loop. To avoid these many statments you can also use two loops:
to read line from text file.
Once line is being read, extract all values using strtok