Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. [newbie] error C2065: 'b' : undeclared identifier

[newbie] error C2065: 'b' : undeclared identifier

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++visual-studiodata-structureshelp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jon 80
    wrote on last edited by
    #1

    Any idea why doesn't this compile?

    // SieveOfErathostenes.cpp : main project file.

    #include "stdafx.h"
    #include <bitset>
    #include <iostream>
    #include <ctime>

    using namespace System;

    int main(array<System::String ^> ^args)
    {
    const int N = 2000000;
    clock_t cstart = clock();

    **bitset<N + 1> b;**
    int count = 0;
    int i;
    for (i = 2; i <= N; i++)
        b.set(i);
    i = 2;
    
    while (i \* i <= N)
    {
        if (b.test(i))
        {
            count++;
            int k = 2 \* i;
            while (k <= N)
            {
                b.reset(k);
                k += i;
            }
        }
        i++;
    }
    
    while (i <= N)
    {
        if (b.test(i))  count++;
        i++;
    }
    
    clock\_t cend = clock();
    double millis = 1000.0 \* (cend - cstart) / CLOCKS\_PER\_SEC;
    
    cout << count << " primes \\n" << millis << " milliseconds\\n";
    
    return 0;
    

    }

    Errors: Error 4 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes Error 5 error C2228: left of '.set' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes Error 6 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes Error 7 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes Error 8 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes Error 9 error C2228: left of '.reset' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes Error 10 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes Error 11 error C2228: left of '.test' must have

    L N 2 Replies Last reply
    0
    • J jon 80

      Any idea why doesn't this compile?

      // SieveOfErathostenes.cpp : main project file.

      #include "stdafx.h"
      #include <bitset>
      #include <iostream>
      #include <ctime>

      using namespace System;

      int main(array<System::String ^> ^args)
      {
      const int N = 2000000;
      clock_t cstart = clock();

      **bitset<N + 1> b;**
      int count = 0;
      int i;
      for (i = 2; i <= N; i++)
          b.set(i);
      i = 2;
      
      while (i \* i <= N)
      {
          if (b.test(i))
          {
              count++;
              int k = 2 \* i;
              while (k <= N)
              {
                  b.reset(k);
                  k += i;
              }
          }
          i++;
      }
      
      while (i <= N)
      {
          if (b.test(i))  count++;
          i++;
      }
      
      clock\_t cend = clock();
      double millis = 1000.0 \* (cend - cstart) / CLOCKS\_PER\_SEC;
      
      cout << count << " primes \\n" << millis << " milliseconds\\n";
      
      return 0;
      

      }

      Errors: Error 4 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes Error 5 error C2228: left of '.set' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes Error 6 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes Error 7 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes Error 8 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes Error 9 error C2228: left of '.reset' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes Error 10 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes Error 11 error C2228: left of '.test' must have

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      is this the right forum for you? apart from your Java note, I see code that looks like regular C++, not managed C++/CLI which is the subject of this forum. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


      J 1 Reply Last reply
      0
      • J jon 80

        Any idea why doesn't this compile?

        // SieveOfErathostenes.cpp : main project file.

        #include "stdafx.h"
        #include <bitset>
        #include <iostream>
        #include <ctime>

        using namespace System;

        int main(array<System::String ^> ^args)
        {
        const int N = 2000000;
        clock_t cstart = clock();

        **bitset<N + 1> b;**
        int count = 0;
        int i;
        for (i = 2; i <= N; i++)
            b.set(i);
        i = 2;
        
        while (i \* i <= N)
        {
            if (b.test(i))
            {
                count++;
                int k = 2 \* i;
                while (k <= N)
                {
                    b.reset(k);
                    k += i;
                }
            }
            i++;
        }
        
        while (i <= N)
        {
            if (b.test(i))  count++;
            i++;
        }
        
        clock\_t cend = clock();
        double millis = 1000.0 \* (cend - cstart) / CLOCKS\_PER\_SEC;
        
        cout << count << " primes \\n" << millis << " milliseconds\\n";
        
        return 0;
        

        }

        Errors: Error 4 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes Error 5 error C2228: left of '.set' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes Error 6 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes Error 7 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes Error 8 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes Error 9 error C2228: left of '.reset' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes Error 10 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes Error 11 error C2228: left of '.test' must have

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        You forgot using namespace std; ;P

        Navaneeth How to use google | Ask smart questions

        1 Reply Last reply
        0
        • L Luc Pattyn

          is this the right forum for you? apart from your Java note, I see code that looks like regular C++, not managed C++/CLI which is the subject of this forum. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


          J Offline
          J Offline
          jon 80
          wrote on last edited by
          #4

          That's what I've been told ma'am :) Btw, that's a note for me...I tend to note sources of references like I used to when I woz at school. http://www.codeproject.com/Forums/1647/C-Cplusplus-MFC.aspx[^]

          Jon

          L L 2 Replies Last reply
          0
          • J jon 80

            That's what I've been told ma'am :) Btw, that's a note for me...I tend to note sources of references like I used to when I woz at school. http://www.codeproject.com/Forums/1647/C-Cplusplus-MFC.aspx[^]

            Jon

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            jon_80 wrote:

            That's what I've been told ma'am

            Luc is not a female name! :-D Best Wishes, -David Delaune

            J 1 Reply Last reply
            0
            • L Lost User

              jon_80 wrote:

              That's what I've been told ma'am

              Luc is not a female name! :-D Best Wishes, -David Delaune

              J Offline
              J Offline
              jon 80
              wrote on last edited by
              #6

              His post did not help much anyway :)

              Jon

              1 Reply Last reply
              0
              • J jon 80

                That's what I've been told ma'am :) Btw, that's a note for me...I tend to note sources of references like I used to when I woz at school. http://www.codeproject.com/Forums/1647/C-Cplusplus-MFC.aspx[^]

                Jon

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                In general I recommend you study and solve the first error message first, so when asking about some questions you should make sure to include the first error message or other symptom. That will make it easier on everyone. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups