hi

i am a beginner with c++. i have a csv file. i want to read particular set of values from a particular column. how can i do it. if possible kindly help me with some sample codes.
thanks in advance

What have you tried for yourself?

This can be tricky depending on the cleanliness of the CSV.
Was it created manually, or with Excel?
Will there be commas in quoted fields?
What compiler are you using?
What techniques are you not allowed to use?

The datas are created by software. the values are like, for example like 3,32 ; 0 ; 22,00 ; 0,2.
it has multiple rows and columns.
i want to read particular set of values from a particular column depending on predefined condition( < or > ).
regarding the techniques, im allowed to use anything.

My technique uses C++/CLI, the System.Core reference and the System, System::Collections::Generic, System::IO and System::Linq namespaces.
I would use the File::ReadAllLines() method to read the entire file at once.

I would then use the Enumerable::Select() method to take each row and pass it off to a method that Splits the row by commas and convert the entire collection into a List of array of strings List<array<String^>^>^ or an array of array of strings array<array<String^>^>^

At that point, I could have access to any of the elements like a two-dimensional array.

A better technique may be to use the OleDb namespace and methods.
The code may be more verbose, but it is a solid technique.

Week-old post is a week-old. Never-the-less!
You can parse CSV's in 3 different ways:

  1. Use a Finite State Machine to parse through the lines. https://stackoverflow.com/a/30338543

  2. Use a RegEx to parse through the lines. (Technically, still an FSM, but smaller.)
    https://stackoverflow.com/questions/18144431/regex-to-split-a-csv

  3. Use a library someone else already wrote. https://github.com/ben-strasser/fast-cpp-csv-parser

Also, a good reference:
https://stackoverflow.com/questions/1120140/how-can-i-read-and-parse-csv-files-in-c

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.