You mean if I would like to use such a .hpp file I will have to download it from boost ?
But what is that header file used for ?
Printable View
You mean if I would like to use such a .hpp file I will have to download it from boost ?
But what is that header file used for ?
If you want to use any of the boost' libraries, then yes, you will have to download them from boost. That doesn't mean that you are not allowed to name your own headers "something.hpp". The extension .hpp is as good as .h -- actually it signals that the header is C++ specific (.c vs. .cpp --> .h vs. .hpp);Quote:
Originally posted by hometown
You mean if I would like to use such a .hpp file I will have to download it from boost ?
But what is that header file used for ?
<boost/any.hpp> is the header that implements the class boost::any. To make a long story short, this class can hold (nearly) any type of variable -- thus the name. Read the boost documentation if you want to know more.
:)Quote:
Originally posted by Gabriel Fleseriu
If you want to use any of the boost' libraries, then yes, you will have to download them from boost. That doesn't mean that you are not allowed to name your own headers "something.hpp". The extension .hpp is as good as .h -- actually it signals that the header is C++ specific (.c vs. .cpp --> .h vs. .hpp);
<boost/any.hpp> is the header that implements the class boost::any. To make a long story short, this class can hold (nearly) any type of variable -- thus the name. Read the boost documentation if you want to know more.
The file extension really doesn't matter, some people do like the hpp, but the standard library has no file extension. You could make up an extension and as long as your compiler knows its a header file it will compile.
I tried making a bunch of files with different extensions, and they all work fine :)Quote:
Originally posted by mwilliamson
The file extension really doesn't matter, some people do like the hpp, but the standard library has no file extension. You could make up an extension and as long as your compiler knows its a header file it will compile.
Thank you very much...
I can't find this part of the standard. What page is thisQuote:
Gabriel Fleseriu
quote:
--------------------------------------------------------------------------------
Originally posted by galathaea
Gabriel, your post is nonstandard because it assumes an ANSI character set...
--------------------------------------------------------------------------------
Bingo!
mentioned on ?
And are you talking about wchar_t /vs char or am I missing
something.
The Standard does not say that the target platform has to have an ASCII character set. For example, some IBM computers use the so called EBCDIC character set, if my memory serves me correctly. If you run my program on such a machine, it printed some bogus string.Quote:
Originally posted by mdmd
I can't find this part of the standard. What page is this
mentioned on ?
And are you talking about wchar_t /vs char or am I missing
something.
oh~~ fantastic~~
This should be fairly standard:
Code:#include <sstream>
#include <algorithm>
#include <iostream>
template <class X> class K
{
std::basic_string<X> b, s;
public:
K(const std::basic_string<X> &z) : b(z)
{
std::for_each(++(s = static_cast<std::ostringstream *>(&(std::ostringstream() << std::endl <<
"!dlrow olleH" << std::ends))->str()).rbegin(), s.rend(), *this);
}
void operator()(std::basic_string<X>::value_type &d) const
{
if(b.find(d) == std::basic_string<std::basic_string<X>::value_type>::npos) std::cout << d;
}
};
int main()
{
K<char> k("abcfgijkmnpqstuvxyz");
return 0;
}
Something easy to understand:
Code:#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
typedef vector<string> StringVector;
typedef StringVector::iterator StringVectorIterator;
typedef ostream_iterator<string> StringOstreamIterator;
int main(int argc, char* argv[])
{
int i;
const int VECTOR_SIZE = 0x05;
char limits[] = {'('-1,'7'};
char mixture[] = {0x1D, 0x27, 0x00, 0x24, 0x24, 0x18, 0x0D, 0x1B, 0x00, 0x15};
StringVector one_word(VECTOR_SIZE);
StringVector another_word(VECTOR_SIZE);
StringVectorIterator start_one_word_it, end_one_word_it;
StringVectorIterator start_another_word_it, end_another_word_it;
StringOstreamIterator out_one_word_it(cout, "");
StringOstreamIterator out_another_word_it(cout, "");
start_one_word_it = one_word.begin();
end_one_word_it = one_word.end();
start_another_word_it = another_word.begin();
end_another_word_it = another_word.end();
for(i =0; i<VECTOR_SIZE; i++)
one_word[i] = mixture[i] + 0x48;
for(; i<VECTOR_SIZE<<1; i++)
another_word[i-VECTOR_SIZE] = mixture[i] + 0x57;
for(i=0; i<limits[0]; i++, next_permutation(start_one_word_it, end_one_word_it));
for(i=0; i<limits[1]; i++, next_permutation(start_another_word_it, end_another_word_it));
copy(start_one_word_it, end_one_word_it, out_one_word_it);
cout << " ";
copy(start_another_word_it, end_another_word_it, out_another_word_it);
cout << "!" << endl ;
return 0;
}
Are you sure that you dont (quietly) assume an ASCII character set?
Well, you got me here... :cool:
For another non-portable one:
This may not work on Mac, Sun et al.Code:#include <stdio.h>
void print_double(double d)
{
unsigned char *p = (unsigned char *) &d;
int last = 0, mode = 0, n;
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 8; ++j) {
if (*p & (1 << j)) {
switch (mode) {
case 0:
mode = 2;
n = 0;
last = 0;
break;
case 1:
case 2:
if (n < 4) {
last = (last << 1) + 1;
++n;
} else {
printf("%c", (last << 1) + ((mode & 2) << 4) + 'B');
mode = 0;
}
break;
case 3:
mode = 1;
n = 0;
last = 0;
break;
}
} else {
switch (mode) {
case 0:
mode = 3;
break;
case 1:
case 2:
if (n < 4) {
last = (last << 1);
++n;
} else {
printf("%c", (last << 1) + ((mode & 2) << 4) + 'A');
mode = 0;
}
break;
case 3:
printf(" ");
mode = 0;
break;
}
}
}
++p;
}
}
int main()
{
double d = -5.1642444895816811e+035;
print_double(d);
return 0;
}
Not very obfuscated but portable:
Code:#include <process.h>
#include <iostream.h>
class CState
{
public:
CState();
~CState();
virtual CState* Transit() = 0;
virtual void PrintStatus() = 0;
void PrintError(char* message);
};
class CState0 : public CState
{
public:
CState0();
~CState0();
virtual CState* Transit();
virtual void PrintStatus();
};
class CState1 : public CState
{
public:
CState1();
~CState1();
virtual CState* Transit();
virtual void PrintStatus();
};
class CState2 : public CState
{
public:
CState2();
~CState2();
virtual CState* Transit();
virtual void PrintStatus();
};
class CState3 : public CState
{
static int nCounter;
public:
CState3();
~CState3();
virtual CState* Transit();
virtual void PrintStatus();
};
class CState4 : public CState
{
static int nCounter;
public:
CState4();
~CState4();
virtual CState* Transit();
virtual void PrintStatus();
};
class CState5 : public CState
{
public:
CState5();
~CState5();
virtual CState* Transit();
virtual void PrintStatus();
};
class CState6 : public CState
{
public:
CState6();
~CState6();
virtual CState* Transit();
virtual void PrintStatus();
};
class CState7 : public CState
{
public:
CState7();
~CState7();
virtual CState* Transit();
virtual void PrintStatus();
};
class CState8 : public CState
{
public:
CState8();
~CState8();
virtual CState* Transit();
virtual void PrintStatus();
};
CState::CState()
{
}
CState::~CState()
{
}
void CState::PrintError(char* message)
{
cout << message << endl;
exit(0);
}
CState0::CState0()
{
}
CState0::~CState0()
{
}
CState* CState0::Transit()
{
return new CState1;
}
void CState0::PrintStatus()
{
}
CState1::CState1()
{
}
CState1::~CState1()
{
}
CState* CState1::Transit()
{
return new CState2;
}
void CState1::PrintStatus()
{
cout << 'H';
}
CState2::CState2()
{
}
CState2::~CState2()
{
}
CState* CState2::Transit()
{
return new CState3;
}
void CState2::PrintStatus()
{
cout << 'e';
}
CState3::CState3()
{
}
CState3::~CState3()
{
}
CState* CState3::Transit()
{
switch(nCounter++)
{
case 0: return new CState3;
case 1: return new CState4;
case 2: return new CState7;
default: PrintError("Counter out of range");
}
return NULL;
}
void CState3::PrintStatus()
{
cout << 'l';
}
CState4::CState4()
{
}
CState4::~CState4()
{
}
CState* CState4::Transit()
{
switch(nCounter++)
{
case 0: return new CState8;
case 1: return new CState6;
default: PrintError("Counter out of range");
}
return NULL;
}
void CState4::PrintStatus()
{
cout << 'o';
}
CState5::CState5()
{
}
CState5::~CState5()
{
}
CState* CState5::Transit()
{
return new CState4;
}
void CState5::PrintStatus()
{
cout << 'W';
}
CState6::CState6()
{
}
CState6::~CState6()
{
}
CState* CState6::Transit()
{
return new CState3;
}
void CState6::PrintStatus()
{
cout << 'r';
}
CState7::CState7()
{
}
CState7::~CState7()
{
}
CState* CState7::Transit()
{
return NULL;
}
void CState7::PrintStatus()
{
cout << 'd';
}
CState8::CState8()
{
}
CState8::~CState8()
{
}
CState* CState8::Transit()
{
return new CState5;
}
void CState8::PrintStatus()
{
cout << ' ';
}
int CState3::nCounter = 0;
int CState4::nCounter = 0;
int main(int argc, char* argv[])
{
CState *state = new CState0;
while(state != NULL)
{
CState *temp = state->Transit();
delete state;
state = temp;
if(state != NULL)
state->PrintStatus();
}
return 0;
}