Comma Separated Values

Hello!

How do I save information comma separated, when I write from a C++ to a text file?

If the program read in information about a person, ex name and second name; How do I this information and separate those two with a comma?
Assuming you have something like this:
1
2
3
4
5
struct DATA
{
  string exName;
  string SecondName;
} DataArray[100];

Do this:
1
2
3
4
5
6
std::ofstream fout("output.csv");

for (int i = 0; i < 100; i++)
{
  fout << DataArray[i].exName << ',' << DataArray[i].SecondName << std::endl;
}
Last edited on
Thanks a lot, Stewbond! Now it's working fine!
Topic archived. No new replies allowed.