My compiler wrong?

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

    #1

    My compiler wrong?

    Hi,

    This is actually a continued post. I am soooo confused. Why do the
    following codes not work? Could you please help me out? Or please tell
    me whether it works for you. Then it should be a problem with my
    complier.

    Thanks a lot!!!
    Michael

    #include <iostream>
    #include <vector>

    int main()
    {

    std::vector<int v( 10, 1 );

    for( int i = 0; i < 10; i++ )
    {
    std::cout << "v[ " << i << " ] = " << v.at(i);
    std::cout << std::endl;
    }
    return 0;

    }

  • Default User

    #2
    Re: My compiler wrong?

    Michael wrote:
    Hi,
    >
    This is actually a continued post. I am soooo confused. Why do the
    following codes not work? Could you please help me out? Or please tell
    me whether it works for you. Then it should be a problem with my
    complier.
    What do you mean, "not work"? We have no idea what your expectations
    were, or what the code actually did.




    Brian

    Comment

    • Kai-Uwe Bux

      #3
      Re: My compiler wrong?

      Michael wrote:
      #include <iostream>
      #include <vector>
      >
      int main()
      {
      >
      std::vector<int v( 10, 1 );
      >
      for( int i = 0; i < 10; i++ )
      {
      std::cout << "v[ " << i << " ] = " << v.at(i);
      std::cout << std::endl;
      }
      return 0;
      >
      }
      works for me. output:

      news_groupa.out
      v[ 0 ] = 1
      v[ 1 ] = 1
      v[ 2 ] = 1
      v[ 3 ] = 1
      v[ 4 ] = 1
      v[ 5 ] = 1
      v[ 6 ] = 1
      v[ 7 ] = 1
      v[ 8 ] = 1
      v[ 9 ] = 1


      Best

      Kai-Uwe Bux

      Comment

      • Daniel T.

        #4
        Re: My compiler wrong?

        In article <1155414393.179 647.13450@h48g2 000cwc.googlegr oups.com>,
        "Michael" <michaelnx@gmai l.comwrote:
        Hi,
        >
        This is actually a continued post. I am soooo confused. Why do the
        following codes not work? Could you please help me out? Or please tell
        me whether it works for you. Then it should be a problem with my
        complier.
        >
        Thanks a lot!!!
        Michael
        >
        #include <iostream>
        #include <vector>
        >
        int main()
        {
        >
        std::vector<int v( 10, 1 );
        >
        for( int i = 0; i < 10; i++ )
        {
        std::cout << "v[ " << i << " ] = " << v.at(i);
        std::cout << std::endl;
        }
        return 0;
        >
        }
        The output I got was:

        v[ 0 ] = 1
        v[ 1 ] = 1
        v[ 2 ] = 1
        v[ 3 ] = 1
        v[ 4 ] = 1
        v[ 5 ] = 1
        v[ 6 ] = 1
        v[ 7 ] = 1
        v[ 8 ] = 1
        v[ 9 ] = 1

        Which is exactly what I was expecting to get.

        What did you get? What were you expecting?

        Comment

        • Alex Buell

          #5
          Re: My compiler wrong?

          On 12 Aug 2006 13:26:33 -0700, I waved a wand and this message
          magically appears in front of Michael:
          #include <iostream>
          #include <vector>
          >
          int main()
          {
          >
          std::vector<int v( 10, 1 );
          >
          for (std::vector<in t>::iterator i = v.begin(); i != v.end(); i++)
          std::cout << "v = " << *i << "\n";
          return 0;
          >
          }
          >

          --


          Bien sur mes talons sont toxiques. N'avez vous pas vu ma boite?

          Comment

          • Pierre Barbier de Reuille

            #6
            Re: My compiler wrong?

            Michael wrote:
            Hi,
            >
            This is actually a continued post. I am soooo confused. Why do the
            following codes not work? Could you please help me out? Or please tell
            me whether it works for you. Then it should be a problem with my
            complier.
            >
            Thanks a lot!!!
            Michael
            >
            #include <iostream>
            #include <vector>
            >
            int main()
            {
            >
            std::vector<int v( 10, 1 );
            >
            for( int i = 0; i < 10; i++ )
            {
            std::cout << "v[ " << i << " ] = " << v.at(i);
            std::cout << std::endl;
            }
            return 0;
            >
            }
            >
            Yep, it's working with my compiler and I don't see any problem :/
            What is the error your compiler returns ?

            Pierre

            Comment

            • Michael

              #7
              Re: My compiler wrong?

              the error is
              no matching function for call to `vector<int,all ocator<int::at (int
              &)'

              thanks for all your help! something wrong with my compiler.

              Thanks,
              Michael

              Comment

              • Pierre Barbier de Reuille

                #8
                Re: My compiler wrong?

                Michael wrote:
                the error is
                no matching function for call to `vector<int,all ocator<int::at (int
                &)'
                >
                thanks for all your help! something wrong with my compiler.
                >
                Thanks,
                Michael
                >
                Just to check, try that :


                #include <iostream>
                #include <vector>

                int main()
                {

                std::vector<int v( 10, 1 );

                for( std::vector<int >::size_type i = 0; i < 10; i++ )
                {
                std::cout << "v[ " << i << " ] = " << v.at(i);
                std::cout << std::endl;
                }
                return 0;

                }

                Comment

                • Michael

                  #9
                  Re: My compiler wrong?


                  Pierre Barbier de Reuille wrote:
                  Just to check, try that :
                  >
                  >
                  #include <iostream>
                  #include <vector>
                  >
                  int main()
                  {
                  >
                  std::vector<int v( 10, 1 );
                  >
                  for( std::vector<int >::size_type i = 0; i < 10; i++ )
                  {
                  std::cout << "v[ " << i << " ] = " << v.at(i);
                  std::cout << std::endl;
                  }
                  return 0;
                  >
                  }
                  Thanks for your help! It still did not work.

                  Michael

                  Comment

                  • Ian Collins

                    #10
                    Re: My compiler wrong?

                    Michael wrote:
                    the error is
                    no matching function for call to `vector<int,all ocator<int::at (int
                    &)'
                    >
                    thanks for all your help! something wrong with my compiler.
                    >
                    Either the code you posted wasn't the code you compiled (why vector
                    rather std::vector in the error message?), or you should look for a
                    working compiler.

                    --
                    Ian Collins.

                    Comment

                    • mathieu

                      #11
                      Re: My compiler wrong?


                      Michael wrote:
                      Pierre Barbier de Reuille wrote:
                      >
                      Just to check, try that :


                      #include <iostream>
                      #include <vector>

                      int main()
                      {

                      std::vector<int v( 10, 1 );

                      for( std::vector<int >::size_type i = 0; i < 10; i++ )
                      {
                      std::cout << "v[ " << i << " ] = " << v.at(i);
                      std::cout << std::endl;
                      }
                      return 0;

                      }
                      >
                      Thanks for your help! It still did not work.

                      Are you *sure* you are executing the correct ./a.out. Delete it first
                      and compile your program again.

                      2 cents,
                      Mathieu

                      Comment

                      • Michael

                        #12
                        Re: My compiler wrong?

                        Thanks a lot for all your help!

                        I think there is something wrong with the compiler because it works
                        fine if I use v[i] instead. I do appreciate your time and help!

                        Best Regards,
                        Michael

                        Comment

                        • Alf P. Steinbach

                          #13
                          Re: My compiler wrong?

                          * Michael:
                          >
                          I think there is something wrong with the compiler because it works
                          fine if I use v[i] instead.
                          Is it possible to learn which version of which compiler you're using,
                          under which operating system?

                          --
                          A: Because it messes up the order in which people normally read text.
                          Q: Why is it such a bad thing?
                          A: Top-posting.
                          Q: What is the most annoying thing on usenet and in e-mail?

                          Comment

                          • Michael

                            #14
                            Re: My compiler wrong?


                            Alf P. Steinbach wrote:
                            Is it possible to learn which version of which compiler you're using,
                            under which operating system?
                            >
                            --
                            Sure. I am using Quincy99 on Windows XP.

                            Thanks,
                            Michael

                            Comment

                            • Thomas J. Gritzan

                              #15
                              Re: My compiler wrong?

                              Michael schrieb:
                              Alf P. Steinbach wrote:
                              >
                              >Is it possible to learn which version of which compiler you're using,
                              >under which operating system?
                              >>
                              >--
                              >
                              Sure. I am using Quincy99 on Windows XP.
                              Quincy99 uses gcc 2.95.2, which seems to have problems with namespace std
                              and vector::at(). So it definitly is a compiler issue.

                              --
                              Thomas

                              Comment

                              Working...