AW: AW: [Insight-users] itkBinaryMask3DMeshSource
Luis Ibanez
luis . ibanez at kitware . com
Thu, 25 Sep 2003 18:54:43 -0400
Hi Zein,
You are right, the itk::Point has overloaded the
operator<< for std::ostream. You will see this in
line 212 of
Insight/Code/Common/itkPoint.h
Your code should work fine for a std::ofstream...
BTW, I don't see the std:: namespace in your code,
are you doing "using namespace std" ?
this is bad practice. You should rather do
std::ofstream fout("filename");
fout << pointIterator.Value() << std::endl;
Question:
If you replace "fout" with "std::cout" in your
code, does it prints the points ?
Regards,
Luis
--------------------------
salah wrote:
> Hello Luis,
>
> I am trying to to print the point of a mesh into a file.
> I took this section of code from an example. It works
> just fine when writing to the console. I then tried
> to open a file first and then replaced every std::cout
> with fout as in the following code
>
>
>
>
> ofstream fout("D:/mymesh.cpp");
> typedef MeshType::PointsContainer::ConstIterator PointIterator;
>
> PointIterator pointIterator = mesh->GetPoints()->Begin();
> PointIterator pointEnd = mesh->GetPoints()->End();
> while( pointIterator != pointEnd )
> {
> fout << pointIterator.Value() << "\n";
> ++pointIterator;
> }
> fout.close();
>
>
> This code if producing the follwing error message.
>
> D:\ITK\Examples\DataRepresentation\Mesh\MeshCellVisitorZein.cxx(109) : error C2678:
> binary '<<' : no operator defined which takes a left-hand operand of type 'class ofstream'
> (or there is no acceptable conversion)
>
> I think the std::cout is overloaded by itk to write something
> like "pointIterator.Value()", TRUE?
>
> Please, how can direct my output to a text file, rather than to
> the console.
>
>
> Many Thanks,
>
> Zein
>
>