+ 1

Pls help

I have singly linked list which stores id no and phone no name etc So how can i import from .txt file to my structure and which format i store the datas in my text file

26th Feb 2020, 7:07 PM
Eyasu kibru
Eyasu kibru - avatar
1 Respuesta
+ 1
First, you have to decide on the format. You can practically go with whatever works best for you, but a known format would be "csv" (comma-seperated values), where each line contains the values of a single entry, seperated only by commas, e.g. Name_1,Id_1,Number_1 Name_2,Id_2,Number_2 Again, order is up to you. Whatever is most convenient when reading in the data. Then, you'll have to write a routine to deserialize (read in) nodes from your file. Since you can only read in strings, you'll likely have to convert some of the data before putting in into the node. There is a lot in the STL to help you with this, e.g. stringstreams and conversion functions: https://en.cppreference.com/w/cpp/io/basic_stringstream https://en.cppreference.com/w/cpp/string/basic_string Lastly, here is a short sample code I put together for you. All the deserialization happens inside the read_in() method through some stringstream stuff: https://code.sololearn.com/cE35c11wz9D4/?ref=app
26th Feb 2020, 11:03 PM
Shadow
Shadow - avatar