To publish a program, you can upload it to a web server or ftp server.
To prevent your program from closing (which is perfectly normal, by the way), you can for example wait for keyboard input. Look at the C/C++ new project template to learn how that is done (or look at a "learning C" tutorial.
Please do note that there are forums and collections of frequently asked questions dedicated to general C++ questions such as these (googling for C++ faq may help). We are a Code::Blocks forum.