[newbie] error C2065: 'b' : undeclared identifier
-
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
-
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
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.
-
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
You forgot
using namespace std;
;PNavaneeth How to use google | Ask smart questions
-
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.
-
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
-
jon_80 wrote:
That's what I've been told ma'am
Luc is not a female name! :-D Best Wishes, -David Delaune
-
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
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.