while statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • muser

    while statement

    I have the following problem

    do{

    something;

    while(temp1, != '\n');

    compiler error: syntax error !=.

    How can I write this code differently to accept the !=.


    Also, and there is so many who have helpped in the past and know
    exactly what I'm still working on.

    How do I reset a file that is already been read, in effect once the
    EOF has been reached, how would I be able to read the file over and
    over again? Does the tellg function do this at all?
  • John Carson

    #2
    Re: while statement

    "muser" <charlie12345@h otmail.com> wrote in message
    news:f9a2a258.0 308190742.1728c f40@posting.goo gle.com[color=blue]
    > I have the following problem
    >
    > do{
    >
    > something;
    >
    > while(temp1, != '\n');
    >
    > compiler error: syntax error !=.
    >
    > How can I write this code differently to accept the !=.
    >[/color]

    Get rid of the comma for a start.


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)

    Comment

    • Thomas Matthews

      #3
      Re: while statement

      muser wrote:[color=blue]
      > I have the following problem
      >
      > do{
      >
      > something;
      >
      > while(temp1, != '\n');[/color]
      =-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=
      Remove the ',' (comma):
      while (temp1 != '\n');
      Don't use commas unless you absolutely know what you are doing.
      I rarely use them.
      =-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=

      [color=blue]
      >
      > compiler error: syntax error !=.
      >
      > How can I write this code differently to accept the !=.
      >
      >
      > Also, and there is so many who have helpped in the past and know
      > exactly what I'm still working on.
      >
      > How do I reset a file that is already been read, in effect once the
      > EOF has been reached, how would I be able to read the file over and
      > over again? Does the tellg function do this at all?[/color]
      =-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=
      Once a file has reached EOF, it cannot be read again
      _from_that_posi tion_. You have to clear the status and rewind or
      relocate the file position:
      ifstream myfile;
      myfile.clear(); // Clear the EOF status.
      myfile.seekg(0) ; // Set file position to beginning.
      =-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=-+-=


      --
      Thomas Matthews

      C++ newsgroup welcome message:

      C++ Faq: http://www.parashift.com/c++-faq-lite
      C Faq: http://www.eskimo.com/~scs/c-faq/top.html
      alt.comp.lang.l earn.c-c++ faq:

      Other sites:
      http://www.josuttis.com -- C++ STL Library book

      Comment

      • Ron Natalie

        #4
        Re: while statement


        "muser" <charlie12345@h otmail.com> wrote in message news:f9a2a258.0 308190742.1728c f40@posting.goo gle.com...
        [color=blue]
        > while(temp1, != '\n');
        >
        > compiler error: syntax error !=.
        >
        > How can I write this code differently to accept the !=.[/color]

        Get rid of the comma. Why did you put it there?


        Comment

        • John Harrison

          #5
          Re: while statement

          >[color=blue]
          > How do I reset a file that is already been read, in effect once the
          > EOF has been reached, how would I be able to read the file over and
          > over again? Does the tellg function do this at all?[/color]

          No, you need clear and seekg, in that order.

          my_file.clear() ;
          my_file.seekg(0 );

          john


          Comment

          • muser

            #6
            Re: while statement

            Karl your contribution has appeared to work, thank you for your advice.



            "John Carson" <donaldquixote@ datafast.net.au > wrote in message
            news:<3f424703_ 1@news.brisbane .pipenetworks.c om>...[color=blue]
            > "muser" <charlie12345@h otmail.com> wrote in message
            > news:f9a2a258.0 308190742.1728c f40@posting.goo gle.com[color=green]
            > > I have the following problem
            > >
            > > do{
            > >
            > > something;
            > >
            > > while(temp1, != '\n');
            > >
            > > compiler error: syntax error !=.
            > >
            > > How can I write this code differently to accept the !=.
            > >[/color]
            >
            > Get rid of the comma for a start.[/color]

            Comment

            Working...