GuruC GuruC - 2 months ago 13
C++ Question

How to print a CStringList in c++ using cout

I am new to C++. I was just going through some code and got this doubt.

The code had some CStringList defined somewhere. I wanted to print that to a file. So I wrote the below code

CStringList *stringListDev;
.....
.....
.....
.....
ofstream myfile("example.txt");
for(int i=0; i<stringListDev->Count; i++)
{
myfile << stringListDev[i];
}


I was getting an error saying << not defined on list or something.
Please guide me how to write contents of a stringlist to a file in C++.

Answer

I got it myself. The code was very simple

   CStringList *stringListDev;
   .....
   .....
   .....
   ..... 
   ofstream myfile("example.txt");
   for(int i=0; i<stringListDev->Count; i++)
   {
      myfile << stringListDev->Strings[i];
   }

Thanks for all your responses!! You people rock !!