Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #14768 > unrolled thread

Help in reading a .PLY file via C++

Started bySweety Pie <sweetyp198612@gmail.com>
First post2012-03-06 01:05 -0800
Last post2012-03-08 11:10 +0900
Articles 17 — 10 participants

Back to article view | Back to comp.lang.c++


Contents

  Help in reading a .PLY file via C++ Sweety Pie <sweetyp198612@gmail.com> - 2012-03-06 01:05 -0800
    Re: Help in reading a .PLY file via C++ "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2012-03-06 11:07 +0100
    Re: Help in reading a .PLY file via C++ Quint Rankid <qbr567@gmail.com> - 2012-03-06 06:51 -0800
    Re: Help in reading a .PLY file via C++ nick_keighley_nospam@hotmail.com - 2012-03-06 07:16 -0800
      Re: Help in reading a .PLY file via C++ Sweety <sharmeen.ibrahim@gmail.com> - 2012-03-06 11:03 -0800
        Re: Help in reading a .PLY file via C++ "Asger Joergensen" <Junk@Asger-P.dk> - 2012-03-06 19:47 +0000
          Re: Help in reading a .PLY file via C++ Sweety <sharmeen.ibrahim@gmail.com> - 2012-03-06 11:57 -0800
            Re: Help in reading a .PLY file via C++ "Asger Joergensen" <Junk@Asger-P.dk> - 2012-03-06 20:18 +0000
              Re: Help in reading a .PLY file via C++ "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2012-03-07 09:42 +0100
                Re: Help in reading a .PLY file via C++ "Asger Joergensen" <Junk@Asger-P.dk> - 2012-03-07 08:51 +0000
                Re: Help in reading a .PLY file via C++ "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-03-07 10:37 +0100
    Re: Help in reading a .PLY file via C++ Christian Gollwitzer <auriocus@gmx.de> - 2012-03-06 21:06 +0100
      Re: Help in reading a .PLY file via C++ Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-03-07 11:32 +0000
        Re: Help in reading a .PLY file via C++ Sweety Pie <sweetyp198612@gmail.com> - 2012-03-07 11:45 -0800
          Re: Help in reading a .PLY file via C++ Quint Rankid <qbr567@gmail.com> - 2012-03-07 17:18 -0800
      Re: Help in reading a .PLY file via C++ Sweety Pie <sweetyp198612@gmail.com> - 2012-03-07 11:35 -0800
    Re: Help in reading a .PLY file via C++ Miles Bader <miles@gnu.org> - 2012-03-08 11:10 +0900

#14768 — Help in reading a .PLY file via C++

FromSweety Pie <sweetyp198612@gmail.com>
Date2012-03-06 01:05 -0800
SubjectHelp in reading a .PLY file via C++
Message-ID<44bef0c5-1d48-4a8a-84e7-bbda052c0113@t6g2000pba.googlegroups.com>
Hi,
I need to read the values from this file and save only the numerical
ones in a new file. How can I skip the header which is up to
end_header word? how can read each value and save it
Please help me
This is the format of the file:
ply
format ascii 1.0
obj_info is_cyberware_data 1
obj_info is_mesh 0
obj_info is_warped 0
obj_info is_interlaced 1
obj_info num_cols 512
obj_info num_rows 400
obj_info echo_rgb_offset_x 0.013000
obj_info echo_rgb_offset_y 0.153600
obj_info echo_rgb_offset_z 0.172000
obj_info echo_rgb_frontfocus 0.930000
obj_info echo_rgb_backfocus 0.012660
obj_info echo_rgb_pixelsize 0.000010
obj_info echo_rgb_centerpixel 232
obj_info echo_frames 512
obj_info echo_lgincr 0.000500
element vertex 40256
property float x
property float y
property float z
element range_grid 204800
property list uchar int vertex_indices
end_header
-0.06325 0.0359793 0.0420873
-0.06275 0.0360343 0.0425949
-0.0645 0.0365101 0.0404362
-0.064 0.0366195 0.0414512
-0.0635 0.0367289 0.0424662
-0.063 0.0367836 0.0429737
-0.0625 0.0368247 0.0433543
-0.062 0.0368657 0.0437349
-0.0615 0.0369067 0.0441155
-0.061 0.0369614 0.044623
-0.0605 0.0370162 0.0451305
-0.06 0.0370572 0.0455111
-0.0595 0.0370845 0.0457648
-0.059 0.0371256 0.0461455
-0.0585 0.0371529 0.0463992
-0.058 0.0371666 0.0465261
-0.0575 0.0371666 0.0465261
-0.057 0.0371666 0.0465261
-0.0565 0.0371803 0.046653
-0.056 0.0371803 0.046653
-0.0555 0.0371803 0.046653
-0.055 0.037194 0.0467798
-0.0545 0.0371666 0.0465261
-0.054 0.037194 0.0467798
-0.0535 0.0371803 0.046653
-0.053 0.037194 0.0467798
-0.0525 0.0371803 0.046653 .......................




I have written this code:
#include <iostream>
#include <fstream>

using namespace std;

int main () {
  char myString;
  float aNumber;

  ifstream myfile ("test.txt");

  if (! myfile.is_open())
  {
     cout << "Error opening file";
     exit (1);
  }

  while (! myfile.eof() )
  {
   getline(myfile, myString);
 if(myString !="end_header");
	myFile >> aNumber;
  }
  return 0;
}

-----------------------------------------------------------------------------------
but it is giving error still under getline word, this line (myFile >>
aNumber;) and under the != operator
Any help??
Thanks again

[toc] | [next] | [standalone]


#14771

From"Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl>
Date2012-03-06 11:07 +0100
Message-ID<jj4nlb$ta1$1@news.albasani.net>
In reply to#14768
"Sweety Pie"  wrote in message 
news:44bef0c5-1d48-4a8a-84e7-bbda052c0113@t6g2000pba.googlegroups.com...
>
>Hi,
>I need to read the values from this file and save only the numerical
>ones in a new file. How can I skip the header which is up to
>end_header word? how can read each value and save it
>Please help me
>This is the format of the file:
>ply
>format ascii 1.0
>obj_info is_cyberware_data 1
>obj_info is_mesh 0
>obj_info is_warped 0
>obj_info is_interlaced 1
>obj_info num_cols 512
>obj_info num_rows 400
>obj_info echo_rgb_offset_x 0.013000
>obj_info echo_rgb_offset_y 0.153600
>obj_info echo_rgb_offset_z 0.172000
>obj_info echo_rgb_frontfocus 0.930000
>obj_info echo_rgb_backfocus 0.012660
>obj_info echo_rgb_pixelsize 0.000010
>obj_info echo_rgb_centerpixel 232
>obj_info echo_frames 512
>obj_info echo_lgincr 0.000500
>element vertex 40256
>property float x
>property float y
>property float z
>element range_grid 204800
>property list uchar int vertex_indices
>end_header
>-0.06325 0.0359793 0.0420873
>-0.06275 0.0360343 0.0425949
>-0.0645 0.0365101 0.0404362
>-0.064 0.0366195 0.0414512
>-0.0635 0.0367289 0.0424662
>-0.063 0.0367836 0.0429737
>-0.0625 0.0368247 0.0433543
>-0.062 0.0368657 0.0437349
>-0.0615 0.0369067 0.0441155
>-0.061 0.0369614 0.044623
>-0.0605 0.0370162 0.0451305
>-0.06 0.0370572 0.0455111
>-0.0595 0.0370845 0.0457648
>-0.059 0.0371256 0.0461455
>-0.0585 0.0371529 0.0463992
>-0.058 0.0371666 0.0465261
>-0.0575 0.0371666 0.0465261
>-0.057 0.0371666 0.0465261
>-0.0565 0.0371803 0.046653
>-0.056 0.0371803 0.046653
>-0.0555 0.0371803 0.046653
>-0.055 0.037194 0.0467798
>-0.0545 0.0371666 0.0465261
>-0.054 0.037194 0.0467798
>-0.0535 0.0371803 0.046653
>-0.053 0.037194 0.0467798
>-0.0525 0.0371803 0.046653 .......................
>
>
>
>
>I have written this code:
>#include <iostream>
>#include <fstream>
>
>using namespace std;

namespaces are invented to prevent name collisions. Try to understand why 
using a namespace is against this idea.

>
>int main () {
>  char myString;
>  float aNumber;
>
>  ifstream myfile ("test.txt");
>
>  if (! myfile.is_open())
>  {
>     cout << "Error opening file";
>     exit (1);
>  }
>
>  while (! myfile.eof() )
>  {
>   getline(myfile, myString);
> if(myString !="end_header");
>myFile >> aNumber;
>  }
>  return 0;
>}
>
>-----------------------------------------------------------------------------------
>but it is giving error still under getline word, this line (myFile >>
>aNumber;)

Not clear to me what you mean here. Why don't you check the return value of 
getline?
Sooner or later getline will run against an EOF, but you ignore it and 
continue to use myString.

>and under the != operator

There is an if, but nothing is executed if the condition matches. Usually, 
an if is followed with something to be executed if the condition is 
fulfilled. Now the result is the same as when there was no if at all. Why 
did you place the if here?

For debugging purposes, you can temporarily insert a few lines with "cout << 
__LINE__<< " " << myString << endl;" at some places in your code, so that 
you can follow the flow of your program, or use a debugger.

>Any help??
>Thanks again

[toc] | [prev] | [next] | [standalone]


#14779

FromQuint Rankid <qbr567@gmail.com>
Date2012-03-06 06:51 -0800
Message-ID<3bdcb73c-67fa-4a3a-8c40-b724f17cba76@k6g2000vbz.googlegroups.com>
In reply to#14768
On Mar 6, 4:05 am, Sweety Pie <sweetyp198...@gmail.com> wrote:
> Hi,
> I need to read the values from this file and save only the numerical
> ones in a new file.

> How can I skip the header which is up to
> end_header word?

But evidently you don't want to save all of the numerical values.
What do you mean by "skip" the header?



> how can read each value and save it
> Please help me
> This is the format of the file:
> ply
> format ascii 1.0
> obj_info is_cyberware_data 1

Do some lines have integral values and some real values?

> obj_info is_mesh 0

<snip>

> element vertex 40256
> property float x
> property float y
> property float z

Some lines have no numeric values?

> element range_grid 204800
> property list uchar int vertex_indices
> end_header
> -0.06325 0.0359793 0.0420873
> -0.06275 0.0360343 0.0425949

Do you want to read the lines that have three values each?
> I have written this code:
> #include <iostream>
> #include <fstream>
and
#include <sstream>
#include <string>
and maybe you'll use this too at some point...
#include <vector>
>
> using namespace std;

Please don't use namespaces.  I know that there is some controversy
about when it is proper or reasonable to do this.  I have a simpler
rule.  Don't do it. It'll save you from a debugging session that lasts
into the wee hours.  I really hate those. So I don't do it.  Of course
YMMV and you may not mind. I prefer the easy way out.


>
> int main () {
>   ..char myString;
char?

char stores one single character.  Did you want to do that in a
variable called myString?  I'm not clear on your intent here.

>   //float aNumber;



    std::ifstream myfile("test.txt");
>
>   if (! myfile.is_open())
>   {
>      cout << "Error opening file";
>      exit (1);
>   }





    double aNumber;
    std::string s1,s2; // just temps

    std::string line;

    // we have a variable number of "symbols" per line,
    // so read a line at a time.
    while(std::getline(myfile,line)) {
        std::istringstream ix(line);
        if(ix >> s1 >> s2 >> aNumber) {
             // write aNumber
        }
    }

}

If you want the three values per line that follow end_header, or you
want to discriminate between real and integral values, you have other
problems.  This will just get you the lines that have the form:
string string <number>

If you want to check for "end_header" I suggest reading each of s1, s2
and aNumber from ix individually and checking s1 after you read it.
        if(ix >> s1) {
           // check here for "end_header"
        }
        if(ix >> s2) {
            // whatever you want to do
        }
        if(ix >> aNumber) {
            // write aNumber
        }

I haven't tested any of the above or tried to compile it, so there are
likely to be unanticipated problems, syntax errors or logic errors.


I have a feeling this may be no good to you unless you have a
reasonable c++ text to read through and learn about this.


Quint



[toc] | [prev] | [next] | [standalone]


#14780

Fromnick_keighley_nospam@hotmail.com
Date2012-03-06 07:16 -0800
Message-ID<1380722.174.1331047014082.JavaMail.geo-discussion-forums@vbxv4>
In reply to#14768
On Tuesday, March 6, 2012 9:05:23 AM UTC, Sweety Pie wrote:

> I need to read the values from this file and save only the numerical
> ones in a new file. How can I skip the header which is up to
> end_header word? how can read each value and save it
> Please help me
> This is the format of the file:
> ply
> format ascii 1.0
> obj_info is_cyberware_data 1
> obj_info is_mesh 0
> obj_info is_warped 0

<snip>

> end_header
> -0.06325 0.0359793 0.0420873
> -0.06275 0.0360343 0.0425949
> -0.0645 0.0365101 0.0404362

<snip>

> I have written this code:
> #include <iostream>
> #include <fstream>
> 
> using namespace std;
> 
> int main () {
>   char myString;
>   float aNumber;
> 
>   ifstream myfile ("test.txt");
> 
>   if (! myfile.is_open())
>   {
>      cout << "Error opening file";
>      exit (1);
>   }
> 
>   while (! myfile.eof() )
>   {
>    getline(myfile, myString);
>  if(myString !="end_header");
> 	myFile >> aNumber;
>   }

reread your spec. You want to
   - skip lines until end_header
   - read three numbers per line

that requires two loops, one for the skipping and one for the line reading.

what is the type of myString? What is the type of "end header"? are they the same? What should a C++ programmer normally use to store a string?

Where are you going to store the data? 

>   return 0;
> }
> 
> -----------------------------------------------------------------------------------
> but it is giving error still under getline word, this line (myFile >>
> aNumber;) and under the != operator

meet us half way. Tell us what the errors say.

[toc] | [prev] | [next] | [standalone]


#14784

FromSweety <sharmeen.ibrahim@gmail.com>
Date2012-03-06 11:03 -0800
Message-ID<0c1fbf20-36b1-4805-b571-e359b192c67b@z5g2000pbu.googlegroups.com>
In reply to#14780
On Mar 6, 6:16 pm, nick_keighley_nos...@hotmail.com wrote:
> On Tuesday, March 6, 2012 9:05:23 AM UTC, Sweety Pie wrote:
> > I need to read the values from this file and save only the numerical
> > ones in a new file. How can I skip the header which is up to
> > end_header word? how can read each value and save it
> > Please help me
> > This is the format of the file:
> > ply
> > format ascii 1.0
> > obj_info is_cyberware_data 1
> > obj_info is_mesh 0
> > obj_info is_warped 0
>
> <snip>
>
> > end_header
> > -0.06325 0.0359793 0.0420873
> > -0.06275 0.0360343 0.0425949
> > -0.0645 0.0365101 0.0404362
>
> <snip>
>
>
>
>
>
>
>
>
>
> > I have written this code:
> > #include <iostream>
> > #include <fstream>
>
> > using namespace std;
>
> > int main () {
> >   char myString;
> >   float aNumber;
>
> >   ifstream myfile ("test.txt");
>
> >   if (! myfile.is_open())
> >   {
> >      cout << "Error opening file";
> >      exit (1);
> >   }
>
> >   while (! myfile.eof() )
> >   {
> >    getline(myfile, myString);
> >  if(myString !="end_header");
> >    myFile >> aNumber;
> >   }
>
> reread your spec. You want to
>    - skip lines until end_header
>    - read three numbers per line
>
> that requires two loops, one for the skipping and one for the line reading.
>
> what is the type of myString? What is the type of "end header"? are they the same? What should a C++ programmer normally use to store a string?
>
> Where are you going to store the data?
>
> >   return 0;
> > }
>
> > --------------------------------------------------------------------------- --------
> > but it is giving error still under getline word, this line (myFile >>
> > aNumber;) and under the != operator
>
> meet us half way. Tell us what the errors say.

Thank you very much for all the comments and help. I fixed the
errors .
Here is my code below and I want to read the file until it reaches the
word end header and start saving the floats after it in a new file.
Can some one plz check the code and help me . I didn't manage to write
the loops properly.
Thanks in advance.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  string myString;
  float aNumber;

  ifstream myfile ("test.txt");
 ofstream output;
  if (! myfile.is_open())
  {
     cout << "Error opening file";
     exit (1);
  }
   while (! myfile.eof() )
  {
  do{
  getline(myfile, myString);
  } while(myString !="end_header")

 getline(myfile, myString);
	myfile >> aNumber;
	output << aNumber;
  }
  return 0;
}


[toc] | [prev] | [next] | [standalone]


#14785

From"Asger Joergensen" <Junk@Asger-P.dk>
Date2012-03-06 19:47 +0000
Message-ID<xn0hva76oirgt8001@news.astraweb.com>
In reply to#14784
Hi Sweety

Sweety wrote:

> Here is my code below and I want to read the file until it reaches the
> word end header and start saving the floats after it in a new file.
> Can some one plz check the code and help me . I didn't manage to write
> the loops properly.
> Thanks in advance.
> 
> #include <iostream>
> #include <fstream>
> #include <string>
> using namespace std;
> 
> int main () {
>   string myString;
>   float aNumber;
> 
>   ifstream myfile ("test.txt");
>   if (! myfile.is_open())
>   {
>      cout << "Error opening file";
>      exit (1);
>   }

>   do{
>   getline(myfile, myString);
>   } while( myString !="end_header" && ! myfile.eof() )

>  ofstream output; // You need a filename here
check if open

>   while (! myfile.eof() )
>   {
> 
>  getline(myfile, myString);
> 	myfile >> aNumber;
> 	output << aNumber;
>   }
>   return 0;
> }

You need to tell how You want the output to look
one on each line all in one line space or tab between etc.?
Can there be anything but numbers ? Do You need to convert to
float before You write or can You just write the string You read ?

p.s. please delete unneeded quotes.

Best regards
Asger-P

[toc] | [prev] | [next] | [standalone]


#14786

FromSweety <sharmeen.ibrahim@gmail.com>
Date2012-03-06 11:57 -0800
Message-ID<6d4b36da-c090-4249-bfa7-53e7fc0c2a40@to5g2000pbc.googlegroups.com>
In reply to#14785
On Mar 6, 10:47 pm, "Asger Joergensen" <J...@Asger-P.dk> wrote:
> Hi Sweety
>
>
>
>
>
>
>
>
>
> Sweety wrote:
> > Here is my code below and I want to read the file until it reaches the
> > word end header and start saving the floats after it in a new file.
> > Can some one plz check the code and help me . I didn't manage to write
> > the loops properly.
> > Thanks in advance.
>
> > #include <iostream>
> > #include <fstream>
> > #include <string>
> > using namespace std;
>
> > int main () {
> >   string myString;
> >   float aNumber;
>
> >   ifstream myfile ("test.txt");
> >   if (! myfile.is_open())
> >   {
> >      cout << "Error opening file";
> >      exit (1);
> >   }
> >   do{
> >   getline(myfile, myString);
> >   } while( myString !="end_header" && ! myfile.eof() )
> >  ofstream output; // You need a filename here
>
> check if open
>
> >   while (! myfile.eof() )
> >   {
>
> >  getline(myfile, myString);
> >    myfile >> aNumber;
> >    output << aNumber;
> >   }
> >   return 0;
> > }
>
> You need to tell how You want the output to look
> one on each line all in one line space or tab between etc.?
> Can there be anything but numbers ? Do You need to convert to
> float before You write or can You just write the string You read ?
>
> p.s. please delete unneeded quotes.
>
> Best regards
> Asger-P

Well the output file should have only the numbers and it doesn't
matter if they are all on one line. It should real the whole stream of
numbers and save them with spaces between each number and its
neighbour. There is no need for any conversion.

[toc] | [prev] | [next] | [standalone]


#14789

From"Asger Joergensen" <Junk@Asger-P.dk>
Date2012-03-06 20:18 +0000
Message-ID<xn0hva82jjwgqb002@news.astraweb.com>
In reply to#14786
Hi Sweety

Sweety wrote:

> On Mar 6, 10:47 pm, "Asger Joergensen" <J...@Asger-P.dk> wrote:
> > Hi Sweety
> > You need to tell how You want the output to look
> > one on each line all in one line space or tab between etc.?
> > Can there be anything but numbers ? Do You need to convert to
> > float before You write or can You just write the string You read ?
> 
> Well the output file should have only the numbers and it doesn't
> matter if they are all on one line. It should real the whole stream of
> numbers and save them with spaces between each number and its
> neighbour. There is no need for any conversion.

then try something like this:

while(! myfile.eof() )
{
   getline(myfile, myString);
   output << myString << " ";
}

And please do delete unneeded quotes, it is annoying to have to scroll
through so much meaningless quote.

Best regards
Asger-P

[toc] | [prev] | [next] | [standalone]


#14795

From"Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl>
Date2012-03-07 09:42 +0100
Message-ID<jj770u$jir$1@news.albasani.net>
In reply to#14789
"Asger Joergensen"  wrote in message 
news:xn0hva82jjwgqb002@news.astraweb.com...
>

>then try something like this:
>
>while(! myfile.eof() )
>{
>   getline(myfile, myString);
>   output << myString << " ";
>}
>

Why not:

while (!getline(myfile, myString).eof()) output << myString << ' ';

Otherwise, output is still used when getline hits EOF. 

[toc] | [prev] | [next] | [standalone]


#14796

From"Asger Joergensen" <Junk@Asger-P.dk>
Date2012-03-07 08:51 +0000
Message-ID<xn0hvb4hf1asiiu003@news.astraweb.com>
In reply to#14795
Hi Fred

Fred Zwarts (KVI) wrote:

> 
> Why not:

Change that to "Should be:" and I'll say: Yes Your right. ;-)

Thanks
Best regards
Asger-P

[toc] | [prev] | [next] | [standalone]


#14797

From"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Date2012-03-07 10:37 +0100
Message-ID<jj7a9h$ufg$1@dont-email.me>
In reply to#14795
On 07.03.2012 09:42, Fred Zwarts (KVI) wrote:
> "Asger Joergensen" wrote in message
> news:xn0hva82jjwgqb002@news.astraweb.com...
>>
>
>> then try something like this:
>>
>> while(! myfile.eof() )
>> {
>> getline(myfile, myString);
>> output << myString << " ";
>> }
>>
>
> Why not:
>
> while (!getline(myfile, myString).eof()) output << myString << ' ';
>
> Otherwise, output is still used when getline hits EOF.

Asger's loop can incorrectly try to output `myString` when EOF is 
encountered.

Fred's loop fixes that, but can incorrectly try to output `myString` 
when some failure condition other than EOF, is encountered.

The common idiom is therefore to test the `fail()` member instead of 
`eof()`, i.e.

     while( !getline( f, s ).fail() ) { output << s << ' '; }

and usually that's expressed via the implicit conversion to `bool` in a 
control statement condition, which invokes the `fail()` function,

     while( getline( f, s ) ) { output << s << ' '; }

Note the lack of negation; even thought the implicit conversion invokes 
`fail()`, it negates the result.

Also note the braces. ;-)


Cheers & hth.,

- Alf

[toc] | [prev] | [next] | [standalone]


#14787

FromChristian Gollwitzer <auriocus@gmx.de>
Date2012-03-06 21:06 +0100
Message-ID<jj5qor$hko$1@dont-email.me>
In reply to#14768
Am 06.03.12 10:05, schrieb Sweety Pie:
> I need to read the values from this file and save only the numerical
> ones in a new file. How can I skip the header which is up to
> end_header word? how can read each value and save it
> Please help me

There are better tools than C++ to perform such simple text processing 
tasks. If you have access to a unix shell, try the command

awk '/end_header/ { skip = 1; next } skip' <input.ply >output

It should strip anything up to and including the first line which 
contains end_header.

	Christian

[toc] | [prev] | [next] | [standalone]


#14799

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2012-03-07 11:32 +0000
Message-ID<slrnjlehr6.1ls.grahn+nntp@frailea.sa.invalid>
In reply to#14787
On Tue, 2012-03-06, Christian Gollwitzer wrote:
> Am 06.03.12 10:05, schrieb Sweety Pie:
>> I need to read the values from this file and save only the numerical
>> ones in a new file. How can I skip the header which is up to
>> end_header word? how can read each value and save it
>> Please help me
>
> There are better tools than C++ to perform such simple text processing 
> tasks.

There may be reason he's doing it in C++, but yes, it's worth pointing
out.

> If you have access to a unix shell, try the command
>
> awk '/end_header/ { skip = 1; next } skip' <input.ply >output
>
> It should strip anything up to and including the first line which 
> contains end_header.

Or with Perl:

% perl -ne 'print unless 1 .. /end_header/' input.ply >output

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .

[toc] | [prev] | [next] | [standalone]


#14817

FromSweety Pie <sweetyp198612@gmail.com>
Date2012-03-07 11:45 -0800
Message-ID<be86f2ec-4843-455b-aa95-65d34ac77a5a@pi6g2000pbc.googlegroups.com>
In reply to#14799
Thanks all for the replies. They were so useful to me. but I got
confused a bit about the loops.
I need a loop that will read the input from the file  until the word
"end_header" and ignore all of that input. Then it should start
reading after that word and save the values which are numbers in a new
file separated via space.
can someone just guide me through this plz .Thanks
I have this code and I know it is wrong so please help me.
Thanks again

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  string myString;
  float aNumber;

  ifstream myfile ("test.txt");
 ofstream output;
  if (! myfile.is_open())
  {
     cout << "Error opening file";
     exit (1);
  }

  {
  do{
  getline(myfile, myString);
  } while(myString !="end_header")

while (!getline(myfile, myString).eof()) output << myString << ' ';


  return 0;
}

[toc] | [prev] | [next] | [standalone]


#14823

FromQuint Rankid <qbr567@gmail.com>
Date2012-03-07 17:18 -0800
Message-ID<8c9a05a4-d9d4-44a8-9a6c-5bdb12367bb4@l16g2000vbl.googlegroups.com>
In reply to#14817
On Mar 7, 2:45 pm, Sweety Pie <sweetyp198...@gmail.com> wrote:
> Thanks all for the replies. They were so useful to me. but I got
> confused a bit about the loops.
> I need a loop that will read the input from the file  until the word
> "end_header" and ignore all of that input. Then it should start
> reading after that word and save the values which are numbers in a new
> file separated via space.
> can someone just guide me through this plz .Thanks
> I have this code and I know it is wrong

What was wrong with it exactly?


> so please help me.

Please tell us what problems you encountered when you say the code was
wrong.

Have you tried putting some trace in your code?

Did you edit your test input file to make it a little shorter to see
what happened?  What did happen?






[toc] | [prev] | [next] | [standalone]


#14815

FromSweety Pie <sweetyp198612@gmail.com>
Date2012-03-07 11:35 -0800
Message-ID<f3c7758e-c404-4ce3-b8bc-43c8166afd41@n9g2000pbb.googlegroups.com>
In reply to#14787
Well I have to use c++ cauz I will have Hardware parts later which
cannot get rather than c++
Thanks for the help

[toc] | [prev] | [next] | [standalone]


#14825

FromMiles Bader <miles@gnu.org>
Date2012-03-08 11:10 +0900
Message-ID<8762efn8p9.fsf@catnip.gol.com>
In reply to#14768
Incidentally, if you want to be able to read somewhat arbitrary PLY
files (there's also a binary PLY form, for instance), I recommend
Diego Nehab's "RPLY", which is fairly simple but flexible PLY library.

[It's FOSS, using the MIT license (which, for instance allows it to be
used in propietary software without problems), and easy to embed in
your app just by copying the source files (just two files, rply.c and
rply.h).]

http://w3.impa.br/~diego/software/rply/

-miles

-- 
`Suppose Korea goes to the World Cup final against Japan and wins,' Moon said.
`All the past could be forgiven.'   [NYT]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web