c++

C++ Confusion. Reading Integer From Text File. Convert to ASCII

I am learning C++ for the first time. I have no previous programming background. In the book I have I saw this example. #include <iostream> using::cout; using::endl; int main() { int x = 5; char y = char(x); cout << x << endl; cout << y << endl; return 0; } The example makes sense: print an integer and the AS...

Prevent screen capturing with DirectX

Hi everybody! I would like to render a single image using DirectX. It should work similar to VLC player's "directx video output", were it is not possible to capture a frame using simple screen capturing software or the printscreen-key. It should not be possible (or very difficult) to make a screenshot! Does anyone know how this works i...

c++ programming board

I would like to get into programming in c++ with computer boards. I know there are some educational boards out there that you can hook up to the computer and write simple programs to make lights come on and do simple stuff like that. I was hoping that someone on here could give me some good resources on where i might get these kinds of b...

Pointer to QList - at() vs. [] operator

I'm having problem with understanding some of QList behavior. #include <QList> #include <iostream> using namespace std; int main() { QList<double> *myList; myList = new QList<double>; double myNumber; double ABC; for (int i=0; i<1000000; i++) { myNumber = i; myList->append(myNumber); AB...

bool function problem - always returns true ?

#include <iostream> #include <string> #include <algorithm> #include <cstdlib> #include <cstdio> using namespace std; static bool isanagram(string a, string b); int main(void) { int i,n,j,s; cin >> n; string a, b; cin >> a >> b; if(!isanagram(a,b)) cout << "False" << endl; else cout << "True" << endl; return...

C++ in mobile apps. How does it works

Tell me. How is executed binaries (written in c++ ForExample) in mobiles?? Is it only possible as mixed with J2ME or is it possible to execute "RAW" (like exe file) binary. (In old and new mobiles) ...

Using virtual function in child after casting operation in C++

I have the following code: class A { }; class B : public A { public: virtual void f() {} }; int main() { A* a = new A(); B* b = static_cast<B*>(a); b->f(); } This program fails with a segmentation fault. There are two solutions to make this program work: declare f non-virtual do not call b->f() (i.e. it fai...

Production code for finding junction in a linked list

Hi all, I was asked this question in some interview. I was required to write code for finding junction in a linked list (which is in form of Y with both arms not necessarily equal) for production environment in O(1) space and linear time. I came up with this solution (which i had previously seen somewhere) : 1. Measure lengths of both l...

What does LPCWSTR stand for and how should it be handled with?

First of all, what is it exactly? I guess it is a pointer (LPC means long pointer constant), but what does "W" mean? Is it a specific pointer to a string or a pointer to a specific string? For example I want to close a Window named "TestWindow". HWND g_hTest; LPCWSTR a; *a = ("TestWindow"); g_hTest = FindWindowEx(NULL, NULL, NULL, a);...

Setting a breakpoint on a member function called on a specific object

In gdb, is it possible to set a breakpoint on a member function called on a specific object? To be more specific, imagine class A has a member function Foo(). I'd like the program to stop when Foo is called on a specific object of type A (0xFF11DEADBEAF for example). Is this at all possible? ...

Function has corrupt return value

I have a situation in Visual C++ 2008 that I have not seen before. I have a class with 4 STL objects (list and vector to be precise) and integers. It has a method: inline int id() { return m_id; } The return value from this method is corrupt, and I have no idea why. I'd like to believe its a stack smash, but as far as I know, I ha...

How to store the Visual C++ debug settings?

The debug settings are stored in a .user file which should not be added to source control. However this file does contain useful information. Now I need to set each time I trying to build a fresh checkout. Is there some workaround to make this less cumbersome? Edit: It contains the debug launch parameters. This is often not really a pe...

Where/how to define a template

What is the best pratice in regards to defining a template in C++? template <class T> class A { private: // stuff public: T DoMagic() { //method body } } Or: template <class T> class A { private: // stuff public: T DoMagic(); } template <class T> A::T DoMagic() { // magic } Another way? I seem t...

Compile ACE in Ubuntu 9.10

How do I compile ACE on Ubuntu 9.10. What environment variables do I need to set? ...

Why are string::append operations behaving strangely?

look at the following simple code: #include <iostream> #include <string> using namespace std; int main() { string s("1234567890"); string::iterator i1 = s.begin(); string::iterator i2 = s.begin(); string s1, s2; s1.append(i1, ++i1); s2.append(++i2, s.end()); cout << s1 << endl; cout << s2 << endl; } w...

How to get the object type from a collection (vector) of parent objects using RTTI

Hello, I have a base class which has two child classes derived from it. class A {}; class B : public A {}; class C : public A {}; I have another class that has a pointer to collection of class A members using a vector, something like this: vector<A*> *m_collection; And what I do is to create objects of class B or C and add them to...

in C++ files: what a file opened as an ios::binary differs from one opened as ios::binary | ios::out ?

if i opened a file like: ofstream file("file.dat",ios::binary); or ofstream file("file.dat",ios::binary | ios::out); what can i do with a file opened in the latter form that i can't do with the former form and vice versa thank you ...

Does a type require a default constructor in order to declare an array of it?

I noticed that when you declare an array, the default constructor must be needed. Is that right? Is there any exception? For example, struct Foo{ Foo(int i ) {} }; int main () { Foo f[5]; return 0; } The code above does not compile. ...

What is the best way to split up utility functions in a library to maximize reusability?

I have a recurring problem with a statically linked library I've written (or in some cases, code was accumulated from open sources). This library, MFC Toolbox Library by name, has a lot of free functions, classes, and so on which support MFC programming, Win32 API programming, as well as the venerable C-library and newer C++ standard li...

Why and when should one call _fpreset( )?

The only documentation I can find (on MSDN or otherwise) is that a call to _fpreset() "resets the floating-point package." What is the "floating point package?" Does this also clear the FPU status word? I see documentation that says to call _fpreset() when recovering from a SIGFPE, but doesn't _clearfp() do this as well? Do I need to...