c++

SDL_surface to OpenGL texture

Hey, I have this script to load a SDL_Surface and save it as a OpenGL texture: typedef GLuint texture; texture load_texture(std::string fname){ SDL_Surface *tex_surf = IMG_Load(fname.c_str()); if(!tex_surf){ return 0; } texture ret; glGenTextures(1, &ret); glBindTexture(GL_TEXTURE_2D, ret); glTexImage2D(GL_TEXTURE_2D, 0, 3, te...

Wrong hour in C++

// Simple program to get the date and time on Windows // It compiles and works fine but displays the wrong hour! // Using Visual C++ 2008 Express on XP SP2 #include <Windows.h> #include <iostream> using namespace std; void main() { SYSTEMTIME st; GetSystemTime(&st); cout << "Year : " << st.wYear << "\n"; cout...

C++ Problem initializing an object twice

Hi, I'm relatively new to C++ and am having a hard trouble understanding the instantiation of object and pointers to objects. Whats the difference between these two declaration in terms of memory and usage? : MyClass obj1; MyClass *obj2; And also the specific problem I am having is that I have a class which has an unsigned short arra...

How do I decide whether to use ATL, MFC, Win32 or CLR for a new C++ project?

I'm just starting my first C++ project. I'm using Visual Studio 2008. It's a single-form Windows application that accesses a couple of databases and initiates a WebSphere MQ transaction. I basically understand the differences among ATL, MFC, Win32 (I'm a little hazy on that one actually) and CLR, but I'm at a loss as to how I should choo...

Why does my .push_back() give me an error? (C++)

I initialized a vector of pointers called "antiviral_data", and am able to use antiviral_data.push_back without problems. But when I try to do the same thing with "viral_data" I get an error, because the compiler thinks I am redeclaring "viral_data": vector<virus*> viral_data; vector<virus*>::iterator vI; viral_data.push_back(new X1(9, ...

How to open an std::fstream (ofstream or ifstream) with a unicode filename ?

You wouldn't imagine something as basic as opening a file using the C++ standard library for a Windows application was tricky ... but it appears to be. By Unicode here I mean UTF-8, but I can convert to UTF-16 or whatever, the point is getting an ofstream instance from a Unicode filename. Before I hack up my own solution, is there a pref...

SFINAE with invalid function-type or array-type parameters?

Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main() { char c[sizeof(f<void()>(0)) == 2]; } I expected it doing SFINAE and chosing the second overload, since substitution of T into T[1] yields void [1]() Which is an invalid type, of course. Adjustment of parameter...

Native C++ or .NET for Business App?

Here's the deal: I'm in the process of planning a mid-sized business application that absolutely must support Win2k. AFAIK, official .NET support for Win2k was scrapped a while ago (IIRC, it stopped at version 2.0). Now, I already wrote (ages ago) libraries in C++ that allow me to accomplish the end result (i.e., finish this project) ju...

What is the most random function in C++?

I've used #include<stdlib> #include<time> using namespace std; srand((unsigned)time(0)); int n=(rand()>>8)%4; but what other random functions are there, or what other function could be used as random number generators? EDIT: I don't really have a particular reason for asking this question, I just wanted to know if C++ had any other ...

What C++ library should I use to implement a HTTP client?

I'm looking for a C++ library that implements or enables the implementation of a HTTP client. It should handle cookies as well. What would you propose? Thank you in advance for your time. ...

C3374: can't take address of 'function' unless creating delegate instance

I am having difficulty using a thirdparty library registration function to register a callback. I am writing in C++ CLI, and accessing a library written in C or C++. What does the above compiler error mean? this is the registration function as defined by the vendor: MYCO int WINAPI MyCo_Device_Register_CallbackFunc(LPVOID func, LPVOI...

How to download a file with WinHTTP in C/C++ ?

I know how to download an html/txt page. For example : //Variables DWORD dwSize = 0; DWORD dwDownloaded = 0; LPSTR pszOutBuffer; vector <string> vFileContent; BOOL bResults = FALSE; HINTERNET hSession = NULL, hConnect = NULL, hRequest = NULL; // Use WinHttpOpen to obtain a session handle. hSession = WinHttpOp...

How to create/run a .exe from a program? (C++)

Is it possible (and if so, how) to write a program in C++ that takes parameters, then run that program from another C++ program. Ie: I can create a function that adds two numbers: int add(int a,int b){return a+b;} Is it possible to do the same thing, except instead of a function, a separate C++ .exe? EDIT: Since a lot of people don...

Setting up OpenGL with C++ and Visual Studio 2008

Hey I was wondering if there are any good tutorial out there on how to set this up? I have seen the NeHe tutorials from gamedev.net but some of them seem to be out dated... any clues? thanks ...

Have a C++ Class act like a custom ostream, sstream

I have a C++ class MyObject and I want to be able to feed this data like I would to a osstream (but unlike a direct sstream, have the incoming data be formatted a special way). I can't seem to figure out how to overload a operator for MyObject to eat input given to it. class MyObject { public: ostringstream s; FEEDME }; int m...

64 Bit Error?

relocation truncated to fit: R_X86_64_PC32 against `.bss' I'm getting this linker error in g++ when compiling: The rest of the code isn't material since this definition breaks my compilation. The time function is found in sys/time.h. Compiled on 64-Bit RHEL. long ntime() { struct timeval tp; gettimeofday(&tp, (struct ti...

What is wrong with this setup?

I created a program called test: #include<stdlib.h> #include<iostream> int main() { std::cout<<system("..\\add\\debug\\add.exe 4 8"); while(true); return 0; } add.exe consists of #include<stdlib.h> int main(int argc,char **argv[]) { int n=((unsigned)argv[1]); int m=((unsigned)argv[2]); return(n+m); } so when...

How do I use C++ STL containers in My iPhone App?

I'd like to use an STL set in my iPhone app (which is written in Objective-C in XCode). How do I include set and/or use the standard namespace? In C++ I'd do this: #include<set> using namespace std; // use the set<T> somewhere down here... How can I do this in Objective-C? ...

What Are Some Quirks/Surprises with Using .mm Files in Objective-C?

I want to use some C++ STL collections in my Objective-C iPhone app. Apparently this is possible by giving files the extension ".mm" . What are some of the quirks/surprises associated with this? I want to use the basic containers that I'm familiar with (vector, queue, set, ...) Cheers! ...

How can I make this declaration work?

EDIT: I also got an answer to make sector a vector of vectors: vector<vector<char>>sector; and that gets rid of the rest of my errors. EDIT: I've made sector an array of pointers as someone suggested, and still get three errors: EDIT: I have edited the program, but it has not fixed all of the errors: I have this section of a progra...