c++

Check for a particular string in stdin

Hi, I have a small problem that I don't know how to solve. I have a program which is basically commanded by inputs in stdin. It just keeps running until receives a particular string and then do something else. Ok, I don't have access to the code that controls these inputs but I would like to add a new command. The idea I have is the fo...

how to write this loop better?

i have a code that does something like this: while (doorIsLocked()) { knockOnDoor(); } openDoor(); but i want to be polite and always knock on the door before i open it. i can write something like this: knockOnDoor(); while (doorIsLocked()) { knockOnDoor(); } openDoor(); but i'm just wondering if there's a better idiom that do...

C++ builtin to swap two numerical values?

Does C++ have a built in such as part of STL to swap two numerical values instead of doing: int tmp = var1; var1 = var2; var2 = tmp; Something like this: std::swapValues(var1, var2); Where swapValues is a template. ...

How can I pass map<string,string> into py with API?

C/C++ can use python API to load py. But, only simple type is supported. How can I pass map into py to be a dict with API? Or, which methods are better? ...

QGLWidget::renderText bounding box

Is it possible to get the bounding box of the output of QGLWidget::renderText() in logical or window coordinates? How? ...

Pointer help in C/C++

I want to know about the pointer in C and C++ - how does it help in saving memory? I searched but did not get a satisfactory answer. Please help me out. ...

Manipulating data in Memory instead of file.

consider the function below: int Func(char* filename); int Func(FILE* filepointer); these two do the same, reads alot of data from the given file (by name or pointer), analyze he result, and returns it. I wanna call this function with lots of different data. Therefore I should write data into file, then pass the new filename to Func. ...

Does such an optimization exist in g++?

Consider the following code snippet: list<someClass>& method(); .... list<someClass> test = method(); What will the behavior of this be? Will this code: Return a reference to the someClass instance returned by return value optimization from method(), and then perform someClass's copy constructor on the reference? Avoid calling th...

Is this key-oriented access-protection pattern a known idiom?

Matthieu M. brought up a pattern for access-protection in this answer that i'd seen before, but never conciously considered a pattern: class SomeKey { friend class Foo; SomeKey() {} // possibly make it non-copyable too }; class Bar { public: void protectedMethod(SomeKey); }; Here only a friend of the key class has a...

C++ : automatic const?

When I compile this code: class DecoratedString { private: std::string m_String; public: // ... constructs, destructors, etc std::string& ToString() const { return m_String; } } I get the following error from g++: invalid initialization of reference of type 'std::string&" from expression of type 'const...

Is the gettimeofday function thread safe in Linux?

The current time must be stored globally in order for gettimeofday to work, however I am not sure if the function modifies any global state so that concurrent execution is undefined. ...

Assign std::string from an object using operator=

I'd really like to be able to assign a std::string object from a DecoratedString object that I'm writing. class DecoratedString { private: std::string m_String; public: DecoratedString(const std::string& initvalue) : m_String(initvalue) { } const std::string& ToString() const { return m_String...

SSE Alignment with class

Having some really weird problem and as beginner with c++ I don't know why. struct DeviceSettings { public: ....somevariables DXSize BackbufferSize; ....somemethods }; struct DXPoint; typedef DXPoint DXSize; __declspec(align(16)) struct DXPoint { public: union { struct { int x; int ...

How to use clock() in C++

How do I call clock() in C++? For example, I want to test how much time a linear search takes to find a given element in an array. ...

how pointer in c++ helps in saving memory?

how does pointer in C++ helps in saving memory? ...

The best zip library with public domain license

Does anyone know zip library of C/C++ in public domain license? It meets the following requirements. It operates by the unit like stb_image.c library Supported cross platform. Windows, Mac, Linux and so on. Language is C/C++ License is public domain. ...

Running time of program

The program listed below outputs 0 on the screen. Why? Does it mean that my computer is fast or something is wrong in the code? #include <iostream> #include <cstdio> #include <ctime> using namespace std; int main(){ int j=0; clock_t start=clock(); for (int i=0;i<22220;i++){ i++; j++; j+=i; ...

Output _CrtDumpMemoryLeaks() to a String

Hi, Is it possible to output the contents of the memory leak dump to a String (not a console)? Hopefully yes :) _CrtDumpMemoryLeaks(); // to-string? ...

get global ip address

How can I get ( in C++ ) the global IP address of my computer(windows XP)? ...

from console application to windows form GUI problem

i wrote a console application in visual c++, and now i want to add a GUI to it using windows form. I am new to Windows form. and i have following questions I dont know how to include classes from other .h files in windows form. is library like #include <stdio.h>, #include <stdlib.h>, #include <iostream> in my original project still c...