|
|
Up |
|
|
  |
Author: lazylazy
Date: Mar 31, 2008 23:01
Is there a datatype for byte?
I want to write an API that takes in an array of bytes.
I can use char array, but not sure if sizeof(char) will always be 1
now or in future on all machines(32/64bit) and compilers.
Is sizeof(char) always gauranteed to be one?
Thanks.
|
| |
|
| |
8 Comments |
|
  |
Author: w0rdw0rd
Date: Mar 31, 2008 21:56
Hi guys,
Wondering if you could help me with some errors I've been getting with
the source of a commissioned project. I've got no C++ experience so
I've got no idea what's going on but when I try to compile in debug
mode I get these errors (I've included the lines lines where the
errors happen if it helps):
addrinfo *AI;
\Async.cpp(47) : error C2065: 'addrinfo' : undeclared identifier
\Async.cpp(47) : error C2065: 'AI' : undeclared identifier
\Async.cpp(47) : warning C4552: '*' : operator has no effect; expected
operator with side-effect
if(getaddrinfo(lpszHost, "80", NULL, &AI) != 0)
\Async.cpp(50) : error C2065: 'getaddrinfo' : undeclared identifier
SOCKET s = socket(AI->ai_family, SOCK_STREAM, 0);
\Async.cpp(56) : error C2227: left of '->ai_family' must point to
class/struct/union
|
| Show full article (1.79Kb) |
|
| |
11 Comments |
|
  |
Author: aaragonaaragon
Date: Mar 31, 2008 21:51
Hi everyone,
Can someone explain me the weird error message that I got from this
simple code?
struct VTKP {
std::ostream& os_;
VTKP(std::ostream& os) : os_(os) {}
void operator()(int i) {
os_<
}
};
int main(int argc, char *argv[]) {
|
| Show full article (0.91Kb) |
|
3 Comments |
|
  |
|
|
  |
|
|
  |
|
|
  |
|
|
  |
Author: Markus DehmannMarkus Dehmann
Date: Mar 31, 2008 19:04
I have two integers i1 and i2, the second of which is guaranteed to be
between 0 and 99, and I encode them into one double:
double encoded = (double)i1 + (double)i2 / (double)100;
So, for example, 324 and 2 become 324.02. Now I want to decode them
using the function given below but it decodes the example as 324 and
1, instead of 324 and 2.
Can anyone tell me what's wrong and how to do this right? (my code see
below)
Thanks!
Markus
#include
void decode(double n, int& i1, int& i2){
i1 = int(n);
double rest = n - int(n);
i2 = int(rest * 100.0); // i2 is 1, should be
2
}
|
| Show full article (0.80Kb) |
|
6 Comments |
|
  |
Author: yogi_bear_79yogi_bear_79
Date: Mar 31, 2008 18:15
I am passing a whole number integer to this function, it converts the
integer to a string, then I want to add commas so a number like
1234567 shows as 1,234,567. I am a little stuck, I belive the loop is
reading the string from right to left which led me to try decrementing
the loop, but a number like 12345 shows up like 123,45. Or is there a
better way all together to achive ths.
string toStr(int &i)
{
std::string s;
std::stringstream out;
out << i;
s = out.str();
for(size_t x = s.size(); x > 0;
--){
if(x != s.size() && x%%3 == 0)
s.insert(x,",");
}
return s;
}
|
| |
|
18 Comments |
|
  |
|
|
  |
|
|
|
|
|
|
|