Selecting specific rows from .csv file and saving them to a new .csv file

Hi,

New to c++ and the site. Please be gentle!

I have a small project that I'm working on were I need to read a csv file. The file has 3 rows, this first column in each row has a unique name that I would like to use to select that entire row and copy to a new file. The thought is hopefully this can be done with a larger number of rows.

Has anyone encountered this before, know how it could be done or any examples?

I have searched quite a bit but get some conflicting ways.

Thanks
Last edited on
Since you are new to C++ I would suggest to start small.
Write a simple program that can read all the 3 lines from the file and display them on the console.

Hi, Thanks for your reply. I have just successfully done this. Now I need to work out how to select each row that contains the key word and write them to a new file.
OK, now you read the first column of each line and use this value as the filename for the outputfile.
To read the first column you could use the string.find / str.substr method or getline with delimiter.
Then you write the line to the outputfile.
Great I will give this a go Thanks
Why C++?

If you just need to copy some lines from one file, then use existing tools.
Windows has findstr and GNU has grep.
To begin with its just a simple copy of a few string but its also object oriented programming this is why it must use c++
Last edited on
Topic archived. No new replies allowed.