c++

C++ Array initialization

Hi all, the code below gives compilation error when I try to create test t[2]; because there is no default constructor for this. But if I create Test t[2] = {test(1,2), test(2,3)}; Then it works fine. 1)But think of a situation, if we want to create more then 100 array element. We need to create 100 element in the curly braces like.....

UTF-8 output on Windows XP console

The following code shows unexpected behaviour on my machine (I'm using Visual C++ 2008 SP1 on Windows XP here): int main() { SetConsoleOutputCP( CP_UTF8 ); std::cout << "\xc3\xbc"; int fail = std::cout.fail() ? '1': '0'; fputc( fail, stdout ); fputs( "\xc3\xbc", stdout ); } I simply compiled with cl /EHsc...

What limits my use of the stack in terms of memory?

In windows (or any other OS for that matter) what determines how much stack I can use? The name of this very website makes me assume it's possible to run out of stack so should I avoid putting large amounts of data on the stack? ...

Specification of source charset encoding in MSVC++, like gcc "-finput-charset=CharSet"

Hello, I want to create some sample programs that deal with encodings, specifically I want to use wide strings like: wstring a=L"grüßen"; wstring b=L"שלום עולם!"; wstring c=L"中文"; Because these are example programs. This is absolutely trivial with gcc that treats source code as UTF-8 encoded text. But,straightforward compilation do...

Joining a boost::thread instance in the destructor

I'm seeing an issue where a call to boost's thread->join in a destructor leads to a deadlock. I don't understand why, and I'm not too keen on keeping code that just works (and I don't understand why it does) in the project. Class declaration (I've stripped the run() method of try/catch for brevity: according to the boost thread documen...

not declared in this scope

I'm getting an error msg DataReader.h:13: error: 'String' was not declared in this scope DataReader.cpp:5: error: redefinition of 'std::vector<Data*, std::allocator<Data*> > DataReader' DataReader.h:13: error: 'std::vector<Data*, std::allocator<Data*> > DataReader' previously declared here DataReader.cpp:5: error: 'String' was not decla...

How do I declare a string without assigning a value in C++?

I know that for an integer, you can use: int value; I tried: string str; but Visual C++ gave me an error. How do I declare it without assigning a value, then using cin >> str later on to assign it? ...

building a C++ project on Linux platform (or more specifically: building CLIPS on Ubuntu 9.10)

I'm in the process of moving from XP to Linux. (I'm new to Linux) I have succesfully installed CLIPs on Ubuntu, using the SPM. I would however, like to build CLIPS from the sources - since I will be extending its current functionality. I have downloaded the CLIPS sources (v6.2.4) from http://sourceforge.net/projects/clipsrules/files/C...

C++ university course

Hi there Do you know any university which has his C++ course available online? I'm looking for something similar with MIT style(lecture notes, projects and examples, assignments, exams, solutions and video content ) this is what I've found on MIT, but id doesn't have video content. ...

C++: std::string in a multi-threaded program

Given that: 1) The C++03 standard does not address the existence of threads in any way 2) The C++03 standard leaves it up to implementations to decide whether std::string should use Copy-on-Write semantics in its copy-constructor 3) Copy-on-Write semantics often lead to unpredictable behavior in a multi-threaded program I come to the...

How can a client gracefully detect when a server disconnects?

I am working on a client-server application. The client continuously reads data from server, so when a server is closed or disconnects then the client crashes. I tried a try/catch block, but it didn't work. My client application is written in C++. I want the client to display some proper message like "Server disconnected," then exit. ...

How do I create a 64-bit native ATL C++ DLL in Visual Studio 2003?

I have a 32-bit ATL C++ in-proc COM server soultion. How do I port it to 64-bit Windows? I mean how do I make VC++7 emit 64-bit code? Is it possible with Visual Studio 2003? ...

Shorten nested namespace names

If you use nested namespaces, declarations in header files can get very long and unreadable. //header1 namespace test { namespace test1 { class Test {}; } } //namespace In header2 of the program: #include "header1" namespace test2 { class Test1 { void test(test::test1::Test &test) {} void test1(test::test1::Test &test) {} voi...

Is Meyers implementation of Singleton pattern thread safe ?

Is the following implementation, using lazy initialization, of Singleton (Meyers Singleton) thread safe? static Singleton& instance() { static Singleton s; return s; } If not, why and how to make it thread safe? ...

Use Eclipse's code completion for boost

Hi, I would like to profit from Eclipse's code completion for boost:shared_pointer in Eclipse 3.5 with CDT 6.0. Eclipse doesn't offer any completion while I'm writing the following code: #include <boost/shared_ptr.hpp> #include "A.h" typedef boost::shared_ptr<A> aPTR; int main() { aPTR test(new A); test->ge.... // no comp...

How to associate non-member functions with a class in Doxygen?

I'm sure there's some way to do this with the \defgroup, \addgroup and \@{ \@} tags, but after a couple of hours of trial and (obviously) error, I'm asking SO..... I have: class C { public: void foo () const; }; and I have some helper non-member functions that really are part of C's interface, but aren't in the class: std::strin...

How to check if memory has aready been released in Destructor?

I have a simple tank wars style game using the allegro open source library. In my tank class, I initialize arrays of pointers to bitmap objects to 0. Then I create new objects with an allegro function create_bitmap which allocates the memory and initializes it. Then I go about my business as usual. The problem is, when I go to releas...

Why does everybody use unanchored namespace declarations (i.e. std:: not ::std::)?

It seems to me that using unanchored namespaces is just asking for trouble later when someone puts in a new namespace that happens to have the same name as a root level namespace and mysteriously alters the meaning of a whole lot of programs. So, why do people always say std:: instead of ::std::. Do they really mean to be saying "I wan...

How do I get the full path for a filename command-line argument?

I've found lots of libraries to help with parsing command-line arguments, but none of them seem to deal with handling filenames. If I receive something like "../foo" on the command line, how do I figure out the full path to the file? ...

What's the difference between std::string and std::basic_string? And why are both needed?

What's the difference between std::string and std::basic_string? And why are both needed? ...