c++

find the position of a string in another string

Possible Duplicate: substring algorithm Given two strings, A and B, how to find the first position of B in A? For instance, A = " ab123cdefgcde"; B= "cde" Then the first position of B in A is 5. Is there any trick to solve this problem or just search A from the start? ...

How do I include bitmaps on items I've added to the end of a context menu?

Hi all. I'm currently writing a Windows Explorer Shell Extension. Everything is ok so far but I'm having trouble to insert menu items WITH MenuItemBitmaps at the end of the context menu. Here is the code I used without the bitmaps: HRESULT CSimpleShlExt::QueryContextMenu(HMENU hmenu, UINT /*uMenuIndex*/, UINT uidFirstCmd, UINT /*uidLa...

Simulating mouse clicks on Mac OS X does not work for some applications.

I'm writing an application for Mac OS X 10.6 and later in C++. One part of the application needs to simulate mouse movement and mouse clicks. I do this currently by posting CGEvent objects using CGEventPost(kCGHIDEventTap, event);. This works, for the most part - I can simulate mouse movement and clicks just fine, but it seems to fail i...

is it safe to to destroy a socket object while an asyn_read might be going on in boost.ASIO?

In the following code: tcp::socket socket(io_service); tcp::endpoint ep(boost::asio::ip::address::from_string(addr), i); socket.async_connect(ep, &connect_handler); socket.close(); is it correct to close the socket object, or should I close it only in the connect_handler(), resort to shared_ptr to prolong the life of of the socket...

Protobuf-net - serializing .NET GUID - how to read this in C++??

Hi All. I have serialized an object using Protobuf-net , in my .NET application, with relative ease. I also get the .proto file that protobuf-net generated, using GetProto() command. In the .NET generated .proto file, my GUID fields get a type of "bcl.guid". Now I wish to compile the .proto file in C++ so I can deserialize the data. ...

filling an array with random number

Hi there, I trying to fill an array of 20 ints with numbers from 1-20 in random sequence. here's my code: int lookup[20]={0}; int array[20]={0}; srand(time(NULL)); for(int i=0;i<20;++i){ bool done=false; while(!done){ int n=rand()%20; if(lookup[n]==0){ array[i]=n; lookup[n]=1; done...

How to get instance of nested class in C++

I have the following code: class outer { struct inner { int var1; int var2; inner() { var1 = 1; var2 = 2; } }; inner inner_instance; public: const inner *get_inner() { return &inner_instance; } }; int main(int argc, char *argv[]) { // 1 outer outer_instance; cout << outer_instan...

How do i get menu events from a menu item in the system menu of a console window?

I have added a menu item to the SystemMenu of the console window of my application which i created using the AllocConsole() function. but I could not figure out how to process the events for the menu items I've added. How can i process those menu events? Thank you ...

How to hide completely a QGridLayout?

I have a button followed by a QGridLayout full of widgets. I want to show/hide qgridlayout at every button click, but reading documentation of QGridlayout I see there's no show()/hide() implementation, also no setVisible() method available. How do I achieve this? ...

Does splitting C++ code into multiple translation units introduce overhead on the executable size?

I have some code shared among multiple projects in a static library. Even with function-level linking I get more object code than I'd like to in the output - see another question about that. Surely the most straightforward solution to decreasing the amount of object code linked into the final executable would be to split the translatio...

What does returning zero by convention mean?

Hello, This is likely a stupid question but I always find myself wondering which is the standard. In most (not to say all) C++ first examples you may see the main function returning 0 value. This means the operation went ok or not? 0 --> OK 1 --> No OK. Other --> ? Which is the standard way of doing it? By the way, is it better ...

How to write C .so library to subsitute existing C++ .so library?

Hi, all Let me explain the scenario. We have a legacy C++ compiled .so library. The functions in this library are declared with extern "c" {}, so the library can be used by both C and C++ program, plus, for some reason it was created with--static-libgcc option. This old library is very old and hard to maintain. Now we haved managed to...

Get output of CMD line program from C++ (specifically netstat)

I want to be able to run "netstat -n" and grab the output somehow so I can then write it out to another file. How can I do this in C++ on Windows CE Thankyou Chris ...

C++ private virtual inheritance problem

In the following code, it seems class C does not have access to A's constructor, which is required because of the virtual inheritance. Yet, the code still compiles and runs. Why does it work? class A {}; class B: private virtual A {}; class C: public B {}; int main() { C c; return 0; } Moreover, if I remove the default constr...

gSOAP 2.7.15 Adds a redundant namespace to the message header

Hi, I upgraded my application to use gSOAP 2.7.15 (instead of 2.7.9L). In 2.7.9L I added a code to insert the namespaces to the message header - and it worked fine. In 2.7.15, the namespaces are being inserted automatically but WS-Addressing namespace appears twice!! Any idea?? ...

The Fastest Sorting function

Hello... In C++ I need to sort the arrays that I had written with a fast speed as possible, My Question is What is the Best and the Fastest sorting function to use? Or Just Make One with MY self? ...

How to get the pointer to a shared_ptr?

Hi, gents: I am now hacking an old C code, try to make it more C++/Boost style: there is a resource allocation function looks like: my_src_type* src; my_src_create(&src, ctx, topic, handle_src_event, NULL, NULL); i try to wrap src by a shared_ptr: shared_ptr<my_src_type> pSrc; I forgot to mention just now. I need to do this as a ...

What is the easiest way to insert Data into a mysql DB with C++ ?

Do i need external libraries ? is there any minimalistic example ? ...

Is returning a string literal address from a function safe and portable?

I need a function to return a string that will only be accessed read-only. The string contents is known at compile time so that I will use a string literal anyway. I can return something like std::string: std::string myFunction() { return "string"; } or return const char*: const char* myFunction() { return "string"; } Is the...

Using C++ classes within Objective-C++

I am using a small C++ library in a Cocoa application (atm just a very simple example to learn how I should do it). So I have a small C++ class in a namespace looking like follows: namespace testlib { class Test { public: Test(unsigned a); Test operator+(const Test& other) const; Test operator+(unsigned other) const; Te...