Hi
i want to read the colon separated values from a file as given below.
Name : VIjay
city : XYZ
Address : ABC
etc
etc
.
.

these are the entries in a file and i want to read and save the name and age ie,vijay, XYZ etc etc in separate variables. i want all the string values, if more ,in the separate variable or in an array .
plz help me to solve that.

Recommended Answers

All 2 Replies

Member Avatar for jencas

Use getline() to read lines from the file to a string. Split each line using ':' as the separator. Use an appropriate STL container to store the values.

Use getline() to read lines from the file to a string. Split each line using ':' as the separator. Use an appropriate STL container to store the values.

Thanks for the reply.
I solved this problem. I extracted the lines 1 by 1 using fgets() and used sscanf() to store the values from line in a 2-D 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.