c++

Convert TCHAR * -> std::wstring in both unicode and non-unicode environments

I have some code in a library which has to internally work with wstring, that's all nice and fine. But it's called with a TCHAR string parameter, from both unicode and non-unicode projects, and I'm having trouble finding a neat conversion for both cases. I see some ATL conversions and so on but can't see the right way, without defining ...

io operation using same stream object.

Hello all, I want to perform I/O operation in c++. I want to store a pointer to fstream object and using that same fstream I want to read and write to that file. Is it possible without using two different objects i.e ifstream for reading and ofstream for writing. ...

Problem with ifstream::setbuf in VS2008

What changes are needed when porting "setbuf" in VS2005 to VS2008? I have to modify a project in VS2005 to VS2008 to be able to build it. Below is the line of code that needs to be compiled in VS2008. std::ifstream In; In.setbuf(FileBuffer, BUFFER_REGION_SIZE); When I compile the above code in VS2008, I see the below error. e...

How to move multiple rectangles as collision response?

I'm trying to make a game (using irrlicht engine with c++) where you can trap your enemy using boxes. But I just don't get how to detect what should be moved when a collision between the user and one or more boxes is detected. Another thing is that there will also be some objects called bricks which will be able to block movements. Sinc...

Numerical precision differences between VS6 and VS2008 using C++ ?

I've been working on porting a legacy project from Visual Studio 6 to 2008. After jumping a few hurdles I now have the new project building and executing. However, I've noticed that the output from the two versions of the program are very slightly different, as though the floating-point calculations are not equivalent, despite the fact...

Giving focus to view part of a window (Visual C++)

I need simple solution, without using MFC,ATL,AFX etc. Just like you would include only windows.h . I'm now talking about Windows solution. My problem is that I want to be able set focus back on the view part of a window. My window for example consist of view part, title bar and menu bar. After you press alt, focus jumps to the menu bar...

C++ error in ios_base.h

/usr/include/c++/4.4/bits/ios_base.h: In member function ‘std::basic_ios >& std::basic_ios >::operator=(const std::basic_ios >&)’: /usr/include/c++/4.4/bits/ios_base.h:793: error: ‘std::ios_base& std::ios_base::operator=(const std::ios_base&)’ is private /usr/include/c++/4.4/iosfwd:47: error: within this context /usr/include/c++...

STL iterators and 'const'

I have a problem with what appears to be some sort of implicit casting to const when I use iterators. I'm not really sure which code is relevant (if I did I probably wouldn't be asking this question!) so I will try my best to illustrate my problem. typedef set<SmallObject> Container; //not const void LargeObject::someFunct...

How do I specify include directories using NMake?

I'm trying to use nmake to build the libfcg (http://www.fastcgi.com/), however I'm getting the following error: ..\include\fcgios.h(23) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory I have the Widows SDK installed and the Windows.h file is present in this directory: C:\Program Files\Microsoft S...

Strange visual studio 2008 C++ compiler error

I have three lines of code: //int pi; activation->structSize = sizeof(rmsActivationT); int pi; //program wont compile with this here every time I uncomment the second int pi and comment the first int pi I get this error: syntax error : missing ';' before 'type'. When i uncomment this first int pi and comment the second int pi, my c...

Error 10061 while trying to connect to my own computer

I'm just testing out some basic networking code written in Visual C++. I have a client app and a server app that don't do anything fancy, since I'm just testing - basically, the client sends ASCII-encoded strings to the server and the server sends it back all in caps. Everything works fine when I run both programs on my computer, IF I s...

Good way to learn C/C++ for an otherwise experienced programmer?

I always liked coding and programming but I never got to learn it in a structured way. It has mostly been self study. I learned QBASIC, VB and PL/SQL while I was in school. Not very comprehensively, just enough to write some small fancy programs. Wanted to graduate in Comp science but somehow ended up majoring in something else. I did so...

Windows programing in c++

What is the the name of a good site for Windows programming in C++? ...

Static variables in C++

I ran into a interesting issue today. Check out this pseudo-code: void Loop() { static int x = 1; printf("%d", x); x++; } void main(void) { while(true) { Loop(); } } Even though x is static, why doesn't this code just print "1" every time? I am reinitializing x to 1 on every iteration before I print it. ...

Running c++ from Java problem

Hi Guys I need to compile and run a c++ program from java. I am using Process a = Runtime.getRuntime().exec ("g++ -g function.cpp -o function"); Process b = Runtime.getRuntime().exec ("./function"); the problem is that the output I get from the c++ program is not correct but If I compile and run it myself in the command line it works ...

Disallow fields in descended class C++

Hello StackOverflowers, With a friend, we had following problem recently. There was a base class: class A { public: A() : foo(10) {} virtual int getFoo() const { return foo; } protected: int foo; }; A friend implemented a class deriving from the one above. class B : public A { public: void process() { foo = 666; } p...

Reference-counting of std::string

I'm looking at the code for basic_string (that is bundled with g++ 4.2.1). The copy constructor makes use of a grab() function to "grab" a copy of a string (increment its reference-count): _CharT* _M_grab( const _Alloc& __alloc1, const _Alloc& __alloc2 ) { return (!_M_is_leaked() && __alloc1 == __alloc2) ? _M_refcopy() : _M_clone(__a...

Openmp usage in C++ object constructors

Hello Can I use openmp in C++ objects' constructors? What will be done, when there will be a global static object with such constructor? ...

How do I obtain a value of an HTML field with C#/C++

I'm using HtmlElement to get an HTML element by it's ID and trying to display this value and return it (as a String). The problem is that it sees it as an Object. I have a webBrowser in the code with an HTML file that has: <label id="Address" text="asdf"></label> In my C++ header file I have HtmlElement^ element = this->webBrows...

Problem linking when compliling the boost::program_options example

I am trying to compile the multiple_sources.cpp to compile on my computer. I am running Xubuntu Lucid Lynx fully updated. It will compile without issue with g++ -c multiple_sources.cpp but when I try to link and make an exectuable with g++ multiple_sources.o I get: multiple_sources.cpp:(.text+0x3d): undefined reference to `boost::progr...