I was needing to do something using the standard template library, but everything I tried to use did not seem like it was supported. for example I wanted to use the bitset templat class, but no matter how I tried to reference the bitset feature, the compiler did not seem to recognize it. Is there some setting I need to set for the project that lets me use the features that I assume the GCC compiler supports.
KenBurner
What part of the STL does the GCC compiler with the 2.5.2
Re: What part of the STL does the GCC compiler with the 2.5.
Just in case you didn't get the private email. AFAIK the entire STL is supported. You should have to do nothing more than #include <bitset> and either add a using for std or remember to use the std:: prefix. I just tried a quick example and it compiled without issue.
Because I also want type-ahead to work I always explicitly include the source and library paths in any project. I wrote up a blog post a while ago with the details on doing this.
Because I also want type-ahead to work I always explicitly include the source and library paths in any project. I wrote up a blog post a while ago with the details on doing this.
Re: What part of the STL does the GCC compiler with the 2.5.
Getting started with the STL for the first time was awkward for me. Once I mastered the basics, using other templates became easier. The first template I used was vector. The second was bitset. Understanding how one template work, will help with using the other templates.
Note: The following code was not checked to see if it compiles.
Doing a basic example from main.cpp is pretty straight forward. Its when you want to use in classes for the first time while mastering C++ Object Oriented Programming that it took a couple of tries.
main.cpp
===========
//Note the newer style names do not include .h for C++
// You will still need the .h calls for some of the Netburner stuff.
// For information on bitset:
// http://www.cplusplus.com/reference/stl/bitset/bitset/
#include <bitset>
// Including the C++ print methods. You could use #include <stdio.h> or <cstdio>, newer // style, but I recommend just jumping in. Note, for Netburner iprintf you will need the #include <stdio.h>
#include <iostream>
// The entire legacy C++ method calls are now wrapped in there own namespace.
// You will either make calls like std::cout, std::endl, std::bitset. To avoid having
// to do this. The following will set the namespace. You will need to do it for each // file you use the c++ calls in. If you have a limited number of calls per page, // // then std:: should suffice.
use namespace std;
// We need a constant for our bitset declaration.
// We are going to create a bitset that using 1 BYTE/8bits per item.
// The advantage of bitset over char is we do not have to use the basic
// bitwise operators for flipping bits, etc. For more complicated bit manipulations
// bitwise operators may be needed, but those operators are available through
// bitset.
enum {
BITSET_SIZE = 8
};
void main(void)
{
//Get in the habit of not using numerical constants in your declaration
bitset<BITSET_SIZE> mybits;
// In this example we could initialize the mybits in the above declaration, but
// When you start making classes, this tends to become a problem.
mybits.set(2); // 00000100
}
In C++ classes:
=======================
mybits.h
#include <bitset>
using namespace std;
enum {
BITSET_SIZE = 8
}
Class MyClassBits {
bitset<BITSET_SIZE> mybits;
}
MyClassBits.cpp
// Good practice is to list the #include you use in a file
// even if you inherit from the .h file.
#include <bitset>
#include <iostream>
//This is needed as it is not inherited from .h
using namespace std;
MyClassBits::MyClassBits ()
{
mybits.set(); // This will initialize to 11111111
public:
void someOtherMethod();
}
void MyClassBits::someOtherMethod()
{
// The interested thing about printing bitset is we get the
// 10101011 pattern to see how the value would look.
// This came in handy for working with a PCA9506 IO expander chip
// where I need to compare the bitset to what was being sent to the chip.
// If you are using LED the lit LED's are 1's and the off LED are 0's.
cout << "My Bits: " << mybits << endl;
// What if I need to print the integer value?
// Use mybits.to_ulong()
cout << mybits << " as an integer is: " << mybits.to_ulong() << endl;
}
Note: The following code was not checked to see if it compiles.
Doing a basic example from main.cpp is pretty straight forward. Its when you want to use in classes for the first time while mastering C++ Object Oriented Programming that it took a couple of tries.
main.cpp
===========
//Note the newer style names do not include .h for C++
// You will still need the .h calls for some of the Netburner stuff.
// For information on bitset:
// http://www.cplusplus.com/reference/stl/bitset/bitset/
#include <bitset>
// Including the C++ print methods. You could use #include <stdio.h> or <cstdio>, newer // style, but I recommend just jumping in. Note, for Netburner iprintf you will need the #include <stdio.h>
#include <iostream>
// The entire legacy C++ method calls are now wrapped in there own namespace.
// You will either make calls like std::cout, std::endl, std::bitset. To avoid having
// to do this. The following will set the namespace. You will need to do it for each // file you use the c++ calls in. If you have a limited number of calls per page, // // then std:: should suffice.
use namespace std;
// We need a constant for our bitset declaration.
// We are going to create a bitset that using 1 BYTE/8bits per item.
// The advantage of bitset over char is we do not have to use the basic
// bitwise operators for flipping bits, etc. For more complicated bit manipulations
// bitwise operators may be needed, but those operators are available through
// bitset.
enum {
BITSET_SIZE = 8
};
void main(void)
{
//Get in the habit of not using numerical constants in your declaration
bitset<BITSET_SIZE> mybits;
// In this example we could initialize the mybits in the above declaration, but
// When you start making classes, this tends to become a problem.
mybits.set(2); // 00000100
}
In C++ classes:
=======================
mybits.h
#include <bitset>
using namespace std;
enum {
BITSET_SIZE = 8
}
Class MyClassBits {
bitset<BITSET_SIZE> mybits;
}
MyClassBits.cpp
// Good practice is to list the #include you use in a file
// even if you inherit from the .h file.
#include <bitset>
#include <iostream>
//This is needed as it is not inherited from .h
using namespace std;
MyClassBits::MyClassBits ()
{
mybits.set(); // This will initialize to 11111111
public:
void someOtherMethod();
}
void MyClassBits::someOtherMethod()
{
// The interested thing about printing bitset is we get the
// 10101011 pattern to see how the value would look.
// This came in handy for working with a PCA9506 IO expander chip
// where I need to compare the bitset to what was being sent to the chip.
// If you are using LED the lit LED's are 1's and the off LED are 0's.
cout << "My Bits: " << mybits << endl;
// What if I need to print the integer value?
// Use mybits.to_ulong()
cout << mybits << " as an integer is: " << mybits.to_ulong() << endl;
}