c++

C++ - Simple server which sends simple HTML to clients

Now, I'm just fooling around with this and I'm not sure as to why this isn't working. #include <winsock2.h> #include <ws2tcpip.h> #include <iostream> #include <cassert> const char html[] = "HTTP/1.1 200 OK\r\n" "Connection: close\r\n" "Content-type: text/html\r\n" "\r\n" "<html>\r\n" "<head>\r\n" "<title>Hello, world!</title>\r\n" "</h...

How to save the frame buffer and then retrieve it back..

hi I'm very much new to openGL and I'm trying to do a small project something like a paint tool.. so i just want to save all the things in frame buffer to be saved in a file and to retrieve them back.. ...

VS rand() problem with pthread-win32

I come into a strange problem in pthread programming I've compiled the following code in vs2005 with pthread-w32 #include <cstdio> #include <cstdlib> #include <ctime> #include <pthread.h> #include <windows.h> pthread_mutex_t lock; void* thread1(void *) { int r1; while(true) { pthread_mutex_lock(&lock); // rand is maybe a CS ...

Properties file library for C (or C++)

The title is pretty self-explanatory: does anyone know of a (good) properties file reader library for C or, if not, C++? [Edit: To be specific, I want a library which handles the .properties file format used in Java: http://en.wikipedia.org/wiki/.properties] ...

find if string endswith another string c++

How to find if string endswith another string c++ ...

How to get the size of an Array?

Hello, In C# I use the Length property embedded to the array I'd like to get the size of. How to do that in C++? ...

C++ templates that accept only certain types

In Java you can define generic class that accept only types that extends class of your choice, eg: public class ObservableList<T extends List> { ... } This is done using "extends" keyword. Is there some simple equivalent to this keyword in C++? ...

Getting the name of a DLL from within the dll.

If I have a dll called "foo.dll" and the end user renames it to "bar.dll" and LoadLibrary's it, how can I get the name "bar.dll" from inside my dll? Is it GetModuleFilename(hModule, buffer); ? ...

C++ std::string conversion problem on Windows

Hello, This is my procedure: bool Open(std::string filename) { ... HANDLE hFile = CreateFile(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); ... } Error:'CreateFileW' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR' Types pointed to are unrelated; conversion requires re...

std::string in C#?

Hello, I thought the problem is inside my C++ function,but I tried this C++ Function in C++ dll: bool __declspec( dllexport ) OpenA(std::string file) { return true; } C# code: [DllImport("pk2.dll")] public static extern bool OpenA(string path); if (OpenA(@"E:\asdasd\")) I get an exception that the memory is corrupt,why? If ...

Log4cxx custom appender

Is it possible to write a custom appender for log4cxx and have it configurable via a properties file (like the built-in appenders)? I'd prefer doing this without having to rebuild log4cxx (e.g. by deriving/extending an existing appender), if possible. Can you point me toward an example? ...

Return value optimization in VC2008

Is there other technique like RVO (return value optimization) or NRVO (named return value optimization) that can be use with VC2008? ...

Contiguous VirtualAlloc behaviour on Windows Mobile

I have been optimising memory performance on a Windows Mobile application and have encountered some differences in behaviour between VirtualAlloc on Win32 and Windows CE. Consider the following test: // Allocate 64k of memory BYTE * a = (BYTE *)VirtualAlloc(0, 65536, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); // Allocate a second contig...

Enumerated data types and class APIs in C++

If you're supposed to encapsulate everything inside a class definition, how is it then possible to use enumerated data types with the class? For example I've just written the following code... enum PizzaType {DEEP_DISH, HAND_TOSSED, PAN}; enum PizzaSize {SMALL, MEDIUM, LARGE}; class Pizza { public: Pizza(); void set...

How to copy a byte[] into a char*?

Hello, All I need this for is strcpy(). I want to see whether the first three bytes of a buffer(byte array) are "JMX" as string. This is what I did so far: char * ddj; strcpy( ddj, buffer ); //buffer is BYTE[] if ( strcmp( "JMX", ddj ) == 0 ) //check first three chars are "JMX" { buffer += 20; //increase the index with 20 s...

How to erase element from std::vector<> by index?

If I have a std::vector and I want to delete the x'th element how to do it? std::vector<int> vec; vec.push_back(6); vec.push_back(-17); vec.push_back(12); vec.erase(???); Please help! ...

How to get Current Directory?

Hello, I've been doing this in C# and Delphi ,but C++ is evil.The purpose is to create a file in the current directory(where the executable is running). My code: LPTSTR NPath = NULL; DWORD a = GetCurrentDirectory(MAX_PATH,NPath); HANDLE hNewFile = CreateFile(NPath,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); I get...

Color generation function

Let's consider the following scenario: a function which can generate code colors from white to red, from white to blue, from white to pink, from white to orange, etc. The colors code is in RGB format with values from 0 to 255. Any ideas? Can you give me the pseudocode or link to such algorithm? ...

What is the difference between a .cpp file and a .h file?

Because I've made .cpp files then transfered them into .h files, the only difference I can find is that you can't #include .cpp files. Is there any difference that I am missing? ...

What happens if more than one .cpp file is #included?

Becase I've seen (and used) situations like this: In header.h: class point { public: point(xpos, ypos); int x; int y; }; In def.cpp: #include"header.h" point::point(xpos, ypos) { x = xpos; y = ypos; } In main.cpp: #include"header.h" int main() { point p1(5,6); return 0; } I know the program executes ...