question_id
int64
25
74.7M
answer_id
int64
332
74.7M
title
stringlengths
20
150
question
stringlengths
23
4.1k
answer
stringlengths
20
4.1k
3,136,930
3,137,164
C++ libcurl http response code issues
This issue/quirk/side-effect is driving me crazy. Near the bottom the code, the response code of the HTTP interaction is passed by reference into responseCode_. However it often comes out as 0 even though the site can otherwise be accessed, and returns too quickly to be a timeout... All variables are defined, the code ...
The response code is only going to be set if curl_easy_perform() returns CURLE_OK so you should check that first to make sure curl actually performed the request successfully. Are you sure the callback functions for writing the header and body are set up correctly? Also, make sure curl_global_init(CURL_GLOBAL_ALL) is c...
3,137,105
3,137,392
Sed to remove underscores and promote character
I am trying to migrate some code from an old naming scheme to the new one the old naming scheme is: int some_var_name; New one is int someVarName_: So what I would ilke is some form of sed / regexy goodness to ease the process. So fundamentally what needs to happen is: find lower case word with contained _ replace un...
sed -re 's,[a-z]+(_[a-z]+)+,&_,g' -e 's,_([a-z]),\u\1,g' Explanation: This is a sed command with 2 expressions (each in quotes after a -e.) s,,,g is a global substitution. You usually see it with slashes instead of commas, but I think this is easier to read when you're using backslashes in the patterns (and no commas)...
3,137,113
3,137,154
Organizing test project and main executable - C & C++
I have the following directory structure. root --src ---tests src contains the source & header files (C files) for the application. When this application is built, it generates an executable. tests directory contains unit test cases (C++ files, using UnitTest++ as testing framework) for the application. In the testing...
What I've always done for this is had three projects. I'd have one build setup which builds a static library, containing most of my code. Then I'd have a test project that links with the static library and a project that contains UI code and such that isn't typically unit tested. Because both projects share the same co...
3,137,166
3,137,228
Why does my timer stop ticking?
I'm creating a drawing application that renders OpenGL when it gets a WM_SCROLL or WM_MOUSEMOVE. The thing is that there are a lot of mouse moves and I only need it to render a maximum of 60 frames per second. So I created a bool in my engine class called CanRender. so in my render() proc I do: if(!CanRender) { return;...
Why making it so complicated? Drawing in windows application is usually done only in WM_PAINT message and triggered by RedrawWindow function. You can call RedrawWindow within WM_SCROLL and WM_MOUSEMOVE. Multiple calls to RedrawWindow (WM_PAINT messages) will be collapsed if your application can't keep up with drawing. ...
3,137,231
3,137,240
Is it possible not to include a class variable in a class header file?
I want to hide an implementation in implementation file. If the object is not public, I don't want the object's header to leak everywhere my class is used. Suppose I have header file A.h for my class A: #include "Foo.h" class A{ private: Foo foo; public: do_stuff(); }; Now wherever I would i...
Use a pointer to Foo and allocate it dynamically, rather than using a member object. Then you only need to include Foo.h in A.cpp. class Foo; class A{ private: Foo* foo; public: do_stuff(); }
3,137,267
3,137,288
C++: using std::wstring in API function
I'm using the SHGetSpecialFolderLocation API function. My application is set to "Use Unicode Character Set". Here's what I have so far: int main ( int, char ** ) { LPITEMIDLIST pidl; HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl); /* Confused at this point */ wstring wstrPath; ...
The second parameter is an out parameter, so you can't just pass c_str (which is const) directly. It would probably be simplest just to do: wchar_t wstrPath[MAX_PATH]; BOOL f = SHGetPathFromIDList(pidl, wstrPath); MAX_PATH is currently 260 characters.
3,137,336
3,137,551
difference between cstdint and tr1/cstdint
What is the difference between <cstdint> and <tr1/cstdint>? (apart from that one puts things in namespace std:: and the other in std::tr1::) Since this stuff isn't standard yet I guess it's compiler specific so I'm talking about gcc. To compile with the non-tr1 one I must compile with -std=c++0x, but there is no such r...
At least as far as I know, there was no intent to change <cstdint> between TR1 and C++0x. There's no requirement for #includeing <cstdint> to result in an error though -- officially, it's nothing more or less than undefined behavior. An implementation is allowed to specify exact behavior, and in this case it does.
3,137,601
3,934,294
Preprocessor macro based code yields a C2400 error
#define CANCEL_COMMON_DIALOG_HOOK(name) \ void __declspec(naked) ##name##CancelCommonDialogHook(void) \ { \ __asm \ { \ add esp, [k##name##CancelCommonDialogStackOffset] \ jz RESTORE \ jmp [k##name##CancelCommonDialogNewFileRetnAddr] \ RESTORE: \ pushad ...
Fixed it by enclosing the function body in another scope.
3,137,622
3,137,686
C++ Importing and Renaming/Resaving an Image
Greetings all, I am currently a rising Sophomore (CS major), and this summer, I'm trying to teach myself C++ (my school codes mainly in Java). I have read many guides on C++ and gotten to the part with ofstream, saving and editing .txt files. Now, I am interested in simply importing an image (jpeg, bitmap, not really i...
Renaming an image is typically about the same as renaming any other file. If you want to do more than that, you can also change the data in the Title field of the IPTC metadata. This does not require JPEG decoding, or anything like that -- you need to know the file format well enough to be able to find the IPTC metadat...
3,138,053
3,139,534
SiteLock Implementing IObjectSafety BUT Not Working in IE
I have used the SiteLock 1.15 template to restrict domain access to my ActiveX control so that only a list of pre-approved domain can use it. Everything compiles ok, and even the SiteList.exe application that is supplied with the SiteLock template correctly shows the list of domains that I defined inside the ActiveX Co...
It turns out I had the test website in Exploder's trusted zone, with all security options turned off; so Exploder didn't even negotiate with the IObjectSafety interface. When I modified the security option, Exploder started communicating with the interface so all is rainbows and bubbles.
3,138,090
3,138,154
How to rotate yuv420 data?
I need to know how to rotate an image, which is in yuv420p format by 90 degrees. The option of converting this to rgb, rotating and again reconverting to yuv is not feasible. Even an algorithm would help. Regards, Anirudh.
I suppose it is not planar YUV, if it is it already it's quite easy (skip first and last steps). You meant to have YUV 4:2:0 planar, but then I do not understand why you have difficulties. convert it to a planar first: allocate space for planes and put bytes at right places according to the packed YUV format you have....
3,138,283
3,138,290
CreateThread issue in c under window OS
I have the following code which initiate the thread. int iNMHandleThread = 1; HANDLE hNMHandle = 0; hNMHandle = CreateThread( NULL, 0, NMHandle, &iNMHandleThread, 0, NULL); if ( hNMHandle == NULL) ExitProcess(iNMHandleThread); My question is What will happened if I run this code while the thread already in the runnin...
Each time you call CreateThread, a new thread is started that is independent of any other currently-running threads. Whether your "NMHandle" function is capable of running on more than one thread at a time is up to you: for example, does it rely on any global state?
3,138,732
5,360,631
How to implement Outlook Express alike address field control
I was thinking about inserting some object (button, panel or static text) into textctrl, like Outlook Express does this. You can see from a pic "group1" is an object, you can double click on it, when you delete it, it gets deleted the whole text not just a part of it. I made some research and this text field is ju...
The ability to insert an object is built-in to the RichEdit control, that's what Outlook is using, and you can do the same yourself. It seems you would need to implement your own OLE object for your own item, and then use the RichEdit's COM interface to insert it. You can see a sample on MSDN that gets the COM interfac...
3,138,937
3,139,717
How to convert UTM Coordinate in C to Latitude/Longitude using WGS84 Datum?
Does anyone know where I can find open source code (in c++) that converts a UTM point to Geo (WGS 84)? Thanks, Liran
Take a look at GDAL. Specifically the code used here. There is also a Warp API tutorial here which outlines the basic use of the Warp API. Alternatively, you can use the more lightweight PROJ.4 library (GDAL uses this internally).
3,138,977
5,322,523
Building ActiveQt (COM) applications with MinGW
I am using Qt 4.6.3 with MinGW on Windows to build Qt apps and now need to add a COM interface to my application. I enabled ActiveQt but was getting post-link errors because I was missing a copy of the MIDL compiler. I downloaded a copy of the latest MS Windows SDK, which includes MIDL, but now MIDL complains it cann...
Using the MS compiler and tools seems to be the only reliable way to get this working.
3,139,086
3,139,154
c++ boost conditional remove from container
i want to do something like c# linq style : SomeColection <SomeType> someColection; someColection.Remove(something => something > 2); and it'll remove all the things that are bigger then 2 (or any other boolean condition)... using boost in the project...
First, you need a simple template wrapper: template <class Container, class UnaryPredicate> void erase_if(Container& container, UnaryPredicate pred) { container.erase( std::remove_if(container.begin(), container.end(), pred), container.end() ); } It's a well-known idiom, however it won't be possible with m...
3,139,144
3,139,226
Definitive function for get elapsed time in miliseconds
I have tried clock_gettime(CLOCK_REALTIME) and gettimeofday() without luck - And the most basic like clock(), what return 0 to me (?). But none of they count the time under sleep. I don't need a high resolution timer, but I need something for getting the elapsed time in ms. EDIT: Final program: #include <iostream> #in...
You need to try gettimeofday() again, it certainly count the wall clock time, so it counts when the process sleep as well. long long getmsofday() { struct timeval tv; gettimeofday(&tv); return (long long)tv.tv_sec*1000 + tv.tv_usec/1000; } ... long long start = getmsofday(); do_something(); long long end = ...
3,139,287
3,139,308
question on string in c++
does this work on string in c++? string s="lomi"; cout<<s<<endl; what is bad in this code? #include <iostream> #include <cstring> using namespace std; int main(){ string s=string("lomi"); for (int i=0;i<s.length();i++){ s[i]= s[i]+3; } std::cout<<s<<std::endl; return 0; ...
Yes. (after you have #included the corresponding headers, and using the std namespace, etc.) Edit: What's wrong with your code is you should #include <string> instead of #include <cstring>     cstring is C's string.h header, which defines functions like strlen, strcpy, etc. that manipulates a C string, i.e. char*. ...
3,139,414
3,139,545
Qt programming: More productive in Python or C++?
Trying to dive into Qt big time but haven't done a large project with it yet. Currently using Python, but I've been thinking -- which is really the better language to use in terms of programmer productivity? In most comparisons between the languages, Python is the obvious answer, because you don't have to mess with mem...
My Opinion (having tried out C++ and Python in general and specifically in Qt case): Python always wins in terms of 'programmer productivity' and 'peace of mind'. PyQt represent Qt very well and hence question doesn't remain of "Qt with Python" or "Qt with C++", in general python is more productive unless off-course yo...
3,139,558
3,139,577
Scope of pure virtual functions during derived class destruction - In C++
During destruction of the derived class object, i first hit the derived class destructor and then the base class destructor (which is as expected). But i was curious to find out - at what point does the functions of the derived class go out of scope (are destroyed). Does it happen as soon as the control leaves the deri...
Once the destructor of the most derived class finishes, the dynamic type of the object can be considered that of the next less-derived-type. That is, a call to a virtual method in the base destructor will find that the final overrider at that point in time is at base level. (The opposite occurs during construction) str...
3,139,814
3,139,834
How to refactor an existing class to become polymorphic?
I have a class that is used as a member in many places in my project. Now, instead of this class I want to have a polymorphism, and the actual object will be created by some kind of factory. I have to choose between: Having to change all the places where I use the class - to call the factory and use a pointer instead ...
Change all the places where I use the class to call the factory and use a pointer instead of object directly. That's best. It seems painful at first, but it's clean and more extensible than implementing a wrapper because you didn't feel like doing a search for new MyClass(. Once you list all the place with the new, yo...
3,139,862
3,139,886
Simple simple template returning odd numbers?
EDIT BEFORE YOU READ: Sorry.. I didn't add newline so it appeared jumbled, I can't delete the question because I'm not registered yet, sorry for wasting your time guys. I just used a template for the first time (for finding MIN of two numbers) instead of a macro, and I liked it! But when I tried to modify and make my o...
Try adding linebreaks after the other lines too. What happens is this: it prints min(1.3, 2.2) which is 1.300000 it prints a linebreak it prints add(1, 10), which is 11 it prints add(5.1, 7.34) which is 12.440000 Since there is no linebreak between step 3 and 4, it prints the number directly after each other, making ...
3,140,027
3,140,508
Fixing "comparison is always false ..." warning in GCC
I'm having a problem which I'm sure is simple to fix but I'm at a loss... I have a template that performs the following code: T value = d; if ( std::numeric_limits< T >::is_signed ) { if ( value < 0 ) { *this += _T( "-" ); value = -(signed)value; } } Now for, obvious reasons, GCC is giv...
Simpler solution: template <typename T> inline bool isNegative(T value) { return std::numeric_limits< T >::is_signed && value < 0; // Doesn't trigger warning. } T value = d; if ( isNegative(value) ) // Doesn't trigger warning either. { *this += _T( "-" ); value = -1 * value; }
3,140,088
3,140,194
Test for overhead of virtual functions
I set up a (perhaps very unscientific) small test to determine the overhead of virtual functions in a one-level single inheritance and the results I got were, well, exactly the same when accessing the derived class polymorphically or when accessing it directly. What was a bit surprising was the order of magnitude of co...
Accessing it "directly" is doing the same work as accessing it "indirectly". When you call the function on myderived, the pointer stored there could point to some object of some class derived from derived. The compiler can't assume that it really is a derived object, it might be an object of a further derived class tha...
3,140,190
3,140,221
When is (this != this) in C++?
I have a very strange question. I have a class/function : class MCBSystem { [...] template <class Receiver> void setCallBack(int i, Receiver* receiver, void(Receiver::*function)(void*)) { iCallBacks.at(i) = new CallBack<Receiver>(receiver, function, this); }; }; And I inherit it (multiply) in...
Yes, the this pointer has to be patched to allow for multiple inheritance polymorphism. As a zeroth-order approximation, an instance of a class C that inherits from A and B can be thought to include an instance of A followed by an instance of B. Now if you have a pointer to a C instance and convert that to an instance ...
3,140,294
3,140,326
Any performance reason to put attributes protected/private?
I "learned" C++ at school, but there are several things I don't know, like where or what a compiler can optimize, seems I already know that inline and const can boost a little... If performance is an important thing (gaming programming for example), does putting class attributes not public (private or protected) allow ...
The teachers were right to tell you to use private and protected to hide implementation and to teach you about information hiding instead of propsing questionable performance optimizations. Try to think of an appropriate design first and of performance second, in 99% of the cases this will be the better choice (even in...
3,140,387
3,140,393
What is purpose of _p.h files?
In Qt Source files, there are two versions of header files, such as: qxmlstream.h qxmlstream_p.h Why are there _p.h files?
They're generally private header files, used so that components of a subsystems know about everything but users don't need to. In other words, something that multiple C source files in Qt might want to know about would be in the private header files if the users of Qt didn't need to know about them. One example might b...
3,140,683
3,140,711
what is a good alternative to this ugly construct, in c++?
This is my code (simplification of a real-life problem): class Foo { public: void f(const string& s) { if (s == "lt") { return lt(); } else if (s == "lte") return lte(); } else if (s == "gt") return gt(); } else if (s == "gte") return gte(); } } void lt() { /* skipped *...
There is no reflection in C++. However, something like a std::map<std::string, void (Foo::*)()>should do the trick. EDIT: Here is some ugly code to do it maintainably. Note the following : This can probably be improved in various way Please add code to deal with non-existent tokens. I did no error checking. #define...
3,140,797
3,140,957
Rotate a 2D array in-place without using a new array - best C++ solution?
One of my students asked me this kind of homework with C++ arrays. It seemed quite interesting for me, so, though I have solved this problem, I wanted to share my solution with you and know another variants and opinions. The problem is following: Problem It is given a 2D dynamic quadratic matrix (array) A(nxn). It is r...
Wikipedia has an article on in-place matrix transposition. Consider: a b c e f g x y z transpose: a e x b f y c g z rotated 90 deg CCW: c g z b f y a e x So after you have the transpose, reverse the rows, which you can do in-place easily.
3,140,875
3,140,901
How to get rid of "C++ exception specification ignored" warning
I recently got a dll that has been implemented by others. I have to use it in my application. In the header file of their class they have the function declaration void func1() throw (CCustomException); Now when i compile it am getting the warning, C++ exception specification ignored except to indicate a function i...
Ok, it is a non-answer, but I would throw away the exception specification and never use it again. EDIT: I read too fast, and I didn't see you did not write the class yourself. Best way to get rid of warnings in msvc is via #pragma warning(push) followed by #pragma warning(disable:xxxx) where xxxx is the warning code :...
3,141,087
3,141,107
What is meant with "const" at end of function declaration?
I got a book, where there is written something like: class Foo { public: int Bar(int random_arg) const { // code } }; What does it mean?
A "const function", denoted with the keyword const after a function declaration, makes it a compiler error for this class function to change a member variable of the class. However, reading of a class variables is okay inside of the function, but writing inside of this function will generate a compiler error. Anothe...
3,141,199
3,141,522
If an overridden C++ function calls the parent function, which calls another virtual function, what is called?
I'm learning about polymorphism, and I am confused by this situation: Let's say I have the following C++ classes: class A{ ... virtual void Foo(){ Boo(); } virtual void Boo(){...} } class B : public A{ ... void Foo(){ A::Foo(); } void Boo(){...} } I create an instance...
Unless you qualify a function call with the class, all method calls will be treated equal, that is dynamic dispatch if virtual, static dispatch if not virtual. When you fully qualify with the class name the method you are calling you are effectively disabling the dynamic dispatch mechanism and introducing a direct meth...
3,141,432
3,141,475
Any weird purpose of switch / default in this code?
I am porting some code from C to C++ and I found this code: if(ErrorCode >= SOME_CONSTANT) { Status = RETVAL_OK; switch ( ErrorCode ) { default: Status = RETVAL_FAILED; break; } } This code generates a compilation warning: warning C4065: switch statement contains 'defau...
Two things I can think of: 1) the code was automatically generated 2) the original coder thought they might add different processing for error codes later, but never did. In either case, I can't see any reason not to change it to a simple if statement
3,141,455
3,141,539
cmath compilation error when compiling old C++ code in VS2010
I've inherited a few C++ files and an accompanying makefile, which I'm trying to bring into VS2010 as a solution. I've created an empty project and added the appropriate C++ and header (.hpp) files for one of the makefile targets. When I try to compile the project, however, I immediately get a large number of C2061 (s...
Are you sure it's compiling as C++? Most compilers will compile .C file as C and .cpp files as C++, compiling a C++ file with a C-compiler will probably fail. Also, that code mixes oldstyle ('c') headers and newstyle ('c++') headers. It should be more like this (I doubt that is the error however). #include <fstream> #i...
3,141,555
3,145,269
Are there any tools for tracking down bloat in C++?
A carelessly written template here, some excessive inlining there - it's all too easy to write bloated code in C++. In principle, refactoring to reduce that bloat isn't too hard. The problem is tracing the worst offending templates and inlines - tracing those items that are causing real bloat in real programs. With tha...
Check out Symbol Sort. I used it a while back to figure out why our installer had grown by a factor of 4 in six months (it turns out the answer was static linking of the C runtime and libxml2).
3,141,556
3,172,064
How to setup timer resolution to 0.5 ms?
I want to set a machine timer resolution to 0.5ms. Sysinternal utility reports that the min clock resolution is 0.5ms so it can be done. P.S. I know how to set it to 1ms. P.P.S. I changed it from C# to more general question (thanks to Hans) System timer resolution
NtSetTimerResolution Example code: #include <windows.h> extern "C" NTSYSAPI NTSTATUS NTAPI NtSetTimerResolution(ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution); ... ULONG currentRes; NtSetTimerResolution(5000, TRUE, &currentRes); Link with ntdll.lib.
3,141,572
3,141,783
C++ Map Gives Bus Error when trying to set a value
I have the following function as the constructor for a class: template<typename T> void Pointer<T>::Pointer(T* inPtr) { mPtr = inPtr; if (sRefCountMap.find(mPtr) == sRefCountMap.end()) { sRefCountMap[mPtr] = 1; } else { sRefCountMap[mPtr]++; } } Here is the definition for the map: static std::map<T*,...
From your comments, you say that you're initialising a static Pointer. This most likely means you've encountered the "static initialisation order fiasco" - if two static objects are in different compilation units, then it's not defined which order they're initialised in. So if the constructor of one depends on the othe...
3,141,902
3,142,052
How to extract the contents of an OLE container?
I need to break open a MS Word file (.doc) and extract its constituent files ('[1]CompObj', 'WordDocument' etc). Something like 7-zip can be used to do this manually but I need to do this programatically. I've gathered that a Word document is an OLE container (hence why 7-zip can be used to view its contents) but I can...
It is called Compound Files, part of the Structured Storage API. You start with StgOpenStorageEx(). It buys you little for a Word .doc file, the streams themselves have a sophisticated binary format. To really read the document content you want to use automation, letting Word read the file. That's rarely done in C+...
3,141,907
3,142,036
C++ <algorithm> permutation
Why is this code note working (the code compiles and run fine, but is not actually showing the permutations): int main(int argc, char *argv[]) { long number; vector<long> interval; vector<long>::const_iterator it; cout << "Enter number: "; cin >> number; while(number-->0){ interval.pus...
Permutations are lexicographically ordered, that's what std::next_permutation and std::prev_permutation algorithms traverse. Here you enter the "biggest" permutation, so there's no next one in order.
3,141,963
3,142,074
reversible float sort in c/c++
I need to sort some arrays of floats, modify the values, and then construct an array with the original ordering, but the modified values. In R, I could use the rank() and order() functions to achieve this: v a vector v[order(v)] is sorted v[i] goes in the rank(v)th spot in the sorted vector Is there some equivalent o...
There is the equivalent to the rank function in C++: it's called nth_element and can be applied on any model of Random Access Container (among which vector and deque are prominent). Now, the issue seems, to me, that the operate on values might actually modify the values and thus the ranks would change. Therefore I woul...
3,142,038
13,130,289
QextSerialPort connection problem to Arduino
I'm trying to make a serial connection to an Arduino Diecimila board with QextSerialPort. My application hangs though everytime I call port->open(). The reason I think this is happening is because the Arduino board resets itself everytime a serial connection to it is made. There's a way of not making the board reset de...
I had a similar problem. In my case QExtSerial would open the port, I'd see the RX/TX lights on the board flash, but no data would be received. If I opened the port with another terminal program first QExtSerial would work as expected. What solved it for me was opening the port, configuring the port settings, and then ...
3,142,294
3,142,343
Receiving console output
Is there a way to execute a program and receive the console output in c++ instead of displaying the console window? I am trying to do a command line call but provide a GUI instead of the console output.
You can do this on most systems using popen (or on some compilers _popen). If that isn't versatile enough for your purposes, you'll probably have to do something platform specific (e.g., fork on a POSIX-like system, or CreateProcess on Windows).
3,142,420
3,143,391
Convert some code from C++ to C
Possible Duplicate: C code compiles as C++, but not as C Edit: I recompiled the source for the library as C, and that fixed it. I've got this code I need to use in my application. It's for writing to the serial port, and I can't figure out how to get it to run in C. I've got a version in C++, as well as a version th...
I had to recompile the library as C, then use that version. The existing version was compiled as C++.
3,142,630
3,142,693
Implementation of string literal concatenation in C and C++
AFAIK, this question applies equally to C and C++ Step 6 of the "translation phases" specified in the C standard (5.1.1.2 in the draft C99 standard) states that adjacent string literals have to be concatenated into a single literal. I.e. printf("helloworld.c" ": %d: Hello " "world\n", 10); Is equivalent (synta...
The standard doesn't specify a preprocessor vs. a compiler, it just specifies the phases of translation you already noted. Traditionally, phases 1 through 4 were in the preprocessor, Phases 5 though 7 in the compiler, and phase 8 the linker -- but none of that is required by the standard.
3,142,701
3,142,740
Building in 64 bit Windows on VS2008 gives C2632 error
So I am trying to build an 32 bit application in 64. I am linking to all 64 bit libraries, and I have recompiled everything we used for 64 bit. I am getting weird errors now. I have seen some similar errors over the net but nothing useful in those topics. Any idea what could be wrong that causes this behavior? warning ...
It looks like FLOAT and DOUBLE have been previously #defined to double. This might be a result of another library, although it seems unlikely to be caused by switching to 64-bit compilation. Try doing #undef FLOAT #undef DOUBLE Prior to including windows.h or windef.h or whichever file is directly responsible for the ...
3,142,764
3,143,144
How to switch on the "auto-build" option in VS2008
What option (where it is located in VS2008 menu) is need to be switched on in order VS2008 compile and build solution before launch (native C++ project)? Thanks.
Tools + Options, Projects and Solutions, Build and Run. The setting "On Run, when projects are out of date" is relevant. You'll probably want "Always build". The setting for the next one has "Do not launch" as the only sane option.
3,142,941
3,142,997
Porting C++ code from Windows to Linux - Header files case sensitivity issue
I am porting a C++ large project form Windows to Linux. My C++ files include header files that do not match those on the project directory due to the case sensitivity of file names in Linux file systems. Any help? I would prefer finding a flag for gcc (or ext4 file system) to manual editing or sed'ing my files. Thanks ...
You're out of luck on your preference. Linux is case-sensitive, and always will be. Just identify the names that need to be changed, and sed away.
3,143,000
3,143,117
How do I specify 64-bit machine architecture when building boost libraries with bjam on solaris?
How do I specify 64-bit machine architecture when building boost libraries with bjam on solaris?
Not a real answer, just a note - Sun compiler is something boost has always had trouble with. Only fairly recent versions are supported and you need STLport. Take a look here and here. You might want to play with the [compiler options] part of the module syntax. Edit: Found this specific link that tells this should wor...
3,143,052
3,143,166
C code compiles as C++, but not as C
Possible Duplicate: Convert some code from C++ to C I've got some code that appears to be straight C. When I tell the compiler (I'm using Visual Studio 2008 Express) to compile it as c++, it compiles and links fine. When I try to compile it as C, though, it throws this error: 1>InpoutTest.obj : error LNK2019: unreso...
You're trying to link to a C++ function, from C. That doesn't work due to name mangling- the linker doesn't know where to look for your function. If you want to call a C function from C++, you must mark it extern "C". C does not support extern "C++"- as far as I know. One of the other answers says there is. Alternative...
3,143,068
3,143,450
How can I log which thread called which function from which class and at what time throughout my whole project?
I am working on a fairly large project that runs on embedded systems. I would like to add the capability of logging which thread called which function from which class and at what time. E.g., here's what a typical line of the log file would look like: Time - Thread Name - Function Name - Class Name I know that I can do...
I've worked with a system that had similar requirements (ARM embedded device). We had to build much of it from scratch, but we used some CodeWarrior stuff to do it, and then the map file for the function name lookup. With CodeWarrior, you can get some code inserted into the start and end of each function, and using tha...
3,143,125
3,143,307
reuse function logic in a const expression
I think my question is, is there anyway to emulate the behaviour that we'll gain from C++0x's constexpr keyword with the current C++ standard (that is if I understand what constexpr is supposed to do correctly). To be more clear, there are times when it is useful to calculate a value at compile time but it is also usef...
Template metaprogramming implements logic in an entirely different (and incompatible) way from "normal" C++ code. You're not defining a function, you're defining a type. It just happens that the type has a value associated with it, which is built up from a combination of other types. Because the templates define types,...
3,143,180
3,143,416
How to do static de-initialization if the destructor has side effects and the object is accessed from another static object's destructor?
There is a simple and well-known pattern to avoid the static initialization fiasco, described in section 10.13 of the C++ FAQ Lite. In this standard pattern, there is a trade-off made in that either the constructed object gets never destructed (which is not a problem if the destructor does not have important side effec...
function static objects like global objects are guaranteed to be destroyed (assuming they are created). The order of destruction is the inverse of creation. Thus if an object depends on another object during destruction you must guarantee that it is still available. This is relatively simple as you can force the order ...
3,143,212
3,143,277
conversion from std::vector<char> to wchar_t*
i'm trying to read ID3 frames and their values with TagLib (1) and index them with CLucene (2). the former returns frame ID's as std::vector<char> (3) and the latter writes field names as tchar* [wchar_t* in Linux] (4). i need to make a link between the two. how can i convert from std::vector<char> to wchar_t* by means...
In a simple case where your chars don't contain any accented characters or anything like that, you can just copy each one to the destination and use it: std::vector<char> frameID; std::vector<wchar_t> field_name; std::copy(frameID.begin(), frameID.end(), std::back_inserter(field_name)); lucene_write_field(&field_nam...
3,143,323
3,143,375
To implement properties or not?
I've found a few methods online on how to implement property-like functionality in c++. There seems to be some sound work-arounds for getting it to work well. My question is, with the prevalence of properties in managed langues, should I spend the effort and the possibilty of code-breakage (or whatever) to implement p...
Unless you add reflection to the mix (being able to identify at runtime what properties exist on an object), properties are nothing more than syntactic sugar for getters and setters. Might as well just use getters and setters, in that case. Properties with reflection can indeed be useful for C++ programs, though. Qt ha...
3,143,325
3,143,402
Problem compiling VS8 C++ program with boost signals
So I am wanting to use boost signals in my C++ program. I add: #include <boost/signal.hpp> But I get this error when I build. fatal error LNK1104: cannot open file 'libboost_signals-vc90-mt-gd-1_42.lib' The lib file is not contained within my boost directory. Typing 'libboost_signal' (with variations) into google has...
most of Boost is header-file-only source, so you just need to #include <boost/whatever.hpp> and your done. However, there's a few sections that require a dll - examples are date/time, regex and signals. So yuo need to build the signals dll. instructions are on the boost website and are easy - so easy I've forgotten how...
3,143,832
3,144,095
Problems upgrading VS2008 to VS2010 with Managed and Unmanaged C++
I have a VS2008 Professional solution that I tried to convert to VS2010 Professional (RTM from MSDN download) today and I am experiencing some problems with some unmanaged and managed C++ DLLs that are referenced by a C# application. The C# application is set to target .NET 3.5 (as it was in the VS2008 version) but whe...
Keep your eyes on the ball, the warning you get is for a managed C++ assembly. And the platform target setting for an unmanaged DLL is of no consequence, it won't use any .NET references while being built. Yes, they could not make the platform target setting editable in the C++ IDE, the VS2008 tool chain is required t...
3,143,881
3,144,045
assign values to selective items using STL multimap
typedef std::pair<int, bool> acq_pair; //edge, channel_quality typedef std::pair<int, acq_pair> ac_pair; typedef std::multimap<int, acq_pair> ac_map; typedef ac_map::iterator It_acq; int bits = acq_map.size(); std::cout << "bits = " << bits << std::endl; std::vector<std::vector<bool> > c_flags (1 << bits); for (i =...
The line itc->second.second = c_flags[i][j]; performed in a loop with itc from begin() to end() indeed performs assignment to every value of the map. If the goal was to modify only the j'th value in the map, there was no need for a loop over the entire map: for(size_t j = 0; j < bits; ++j) { std::cout <...
3,143,895
3,143,957
Syntax for std::binary_function usage
I'm a newbie at using the STL Algorithms and am currently stuck on a syntax error. My overall goal of this is to filter the source list like you would using Linq in c#. There may be other ways to do this in C++, but I need to understand how to use algorithms. My user-defined function object to use as my function adap...
(This is only relevant if you didn't accidentally omit some of your code from the question, and may not address the exact problem you're having) You're using is_Selected_Source as a template even though you didn't define it as one. The last line in the 2nd code snippet should read std::bind1st(is_Selected_Source()... O...
3,144,225
3,148,489
Where can I see printf output in an mfc applcation?
Where can I see printf output in an mfc application during debugging? Is there a "console" window I can view in the debugger? (Visual Studio C++ 6.0) Thanks.
If you use the API OutputDebugString, the strings you output will appear in the Visual C Output window (in debug mode). In release mode, you'll need a separate app to capture them, such as DBWIN32.EXE The advantage of using a separate application is that you can get debug output from several applications serialised int...
3,144,340
3,144,970
How to draw on given bitmap handle (C++ / Win32)?
I'm writing an unmanaged Win32 C++ function that gets a handle to a bitmap, and I need to draw on it. My problem is that to draw I need to get a device context, but when I do GetDC (NULL), it gives me a device context for the WINDOW! The parameter for GetDC () is a window handle (HWND), but I don't have a window; just...
In addition to Pavel's answer, the "compatible with the screen" always bugged me too, but, since CreateCompatibleDC(NULL) is universally used for that purpose, I assume it is correct. I think that the "compatible" thing is related just to DDB (the DC is set up to write on the correct DDB type for the current screen), b...
3,144,349
3,144,763
boost threads mutex array
My problem is, I have block matrix updated by multiple threads. Multiple threads may be updating disjoint block at a time but in general there may be race conditions. right now matrix is locked using single lock. The question is, is it possible (and if it is, how?) to implement an efficient array of locks, so that onl...
Use a single lock. But instead of using it to protect the entire matrix use it to guard a std::set (or a boost::unordered_set) which says which blocks are "locked". Something like this. class Block; class Lock_block { public: Lock_block( Block& block ) : m_block(&block) { boost::unique_lock<boost::mutex> ...
3,144,604
3,144,609
'std::vector<T>::iterator it;' doesn't compile
I've got this function: template<typename T> void Inventory::insertItem(std::vector<T>& v, const T& x) { std::vector<T>::iterator it; // doesn't compile for(it=v.begin(); it<v.end(); ++it) { if(x <= *it) // if the insertee is alphabetically less than this index ...
Try this instead: typename std::vector<T>::iterator it; Here's a page that describes how to use typename and why it's necessary here.
3,144,726
3,144,748
Am I failing to follow the standard?
If I have something like this: MyStruct clip; clip = {16, 16, 16, 16}; I get the following warning from the compiler: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x If I active -std=c++0x in the compiler, it does not give any warning. But I'm not sure if I am following the standard...
For initialization you should be able to use MyStruct clip = {16, 16, 16, 16}; but as you discovered in the current C++ standard you can't assign to a bracketed list. In C++1x you can use the extended syntax.
3,144,904
3,144,917
May I take the address of the one-past-the-end element of an array?
Possible Duplicate: Take the address of a one-past-the-end array element via subscript: legal by the C++ Standard or not? int array[10]; int* a = array + 10; // well-defined int* b = &array[10]; // not sure... Is the last line valid or not?
Yes, you can take the address one beyond the end of an array, but you can't dereference it. For your array of 10 items, array+10 would work. It's been argued a few times (by the committee, among others) whether &array[10] really causes undefined behavior or not (and if it does, whether it really should). The bottom lin...
3,145,399
3,145,512
strlen() not working
Basically, I'm passing a pointer to a character string into my constructor, which in turn initializes its base constructor when passing the string value in. For some reason strlen() is not working, so it does not go into the right if statement. I have checked to make sure that there is a value in the variable and the...
Marcin at this point the problem will come down to debugging, I copied your code with some minor omissions and got the correct result. Now it needs to be said, you should be using more C++ idiomatic code. For instance you should be using std::string instead of const char* and std::vector instead of your raw arrays. Her...
3,145,528
3,153,967
Problems with Qt 4.6 in VS 2008
sys info : win xp SP3 , Microsoft Visual Studio 2008 Version 9.0.21022.8 RTM Microsoft .NET Framework Version 3.5 SP1 Qt Add-in 1.1.5 I installed Qt 4.6.3 from the site http://qt.nokia.com/downloads/windows-cpp-vs2008. Then I added the Add-in Qt 1.1.5 and configured the PATH variable. When I open a new QT project , def...
I find solution. Read all the details about the installation on this page >> http://dcsoft.wordpress.com/?aspxerrorpath=/community_server/blogs/dcsoft/archive/2009/03/06/how-to-setup-qt-4-5-visual-studio-integration.aspx. After a whole day of studying and configuration, I finally managed to enable QT 4.6.3. on the VS 2...
3,145,727
3,145,733
Compare a value with all array elements in one statement
For example: if (value == array[size]) //if the value (unique) is present in an array then do something can this be done in one statement without having to call a function or a basic for loop statement?
std::find can do it in one statement, but it's not as trivial as other languages :( int array[10]; if (array + 10 != find(array, array + 10, 7)) { cout << "Array contains 7!"; } Or with std::count: if (int n = count(array, array + 10, 7)) { cout << "Array contains " << n << " 7s!"; }
3,145,799
3,145,825
How to delete a pointer after returning its value inside a function
I have this function: char* ReadBlock(fstream& stream, int size) { char* memblock; memblock = new char[size]; stream.read(memblock, size); return(memblock); } The function is called every time I have to read bytes from a file. I think it allocates new memory every time I use it but how can I free the m...
Dynamic arrays are freed using delete[]: char* block = ReadBlock(...); // ... do stuff delete[] block; Ideally however you don't use manual memory management here: std::vector<char> ReadBlock(std::fstream& stream, int size) { std::vector<char> memblock(size); stream.read(&memblock[0], size); return membloc...
3,145,802
3,155,026
JavaScript Standard Library for V8
In my application, I allow users to write plugins using JavaScript. I embed V8 for that purpose. The problem is that developers can't use things like HTTP, Sockets, Streams, Timers, Threading, Crypotography, Unit tests, et cetra. I searched Stack Overflow and I found node.js. The problem with it is that you can actual...
In the end, I built my own library.
3,145,992
3,167,705
Esoteric JScript hosting problem: where is the error code when IDispatch::Invoke returns SCRIPT_E_PROPAGATE?
Our application hosts the Windows Scripting Host JScript engine and exposes several domain objects that can be called from script code. One of the domain objects is a COM component that implements IDispatch (actually, IDispatchEx) and which has a method that takes a script-function as a call-back parameter (an IDispatc...
Wow, this was seriously underdocumented. The answer is to: In the COM component making a callback into script... QI to get an IDispatchEx pointer on the script function to be called. Construct an object implementing both IServiceProvider & ICanHandleException; e.g. CScriptErrorCapturer. IServiceProvider::QueryServic...
3,146,017
3,146,035
How do I share a constant between C# and C++ code?
I'm writing two processes using C# and WCF for one and C++ and WWSAPI for the second. I want to be able to define the address being used for communication between the two in a single place and have both C# and C++ use it. Is this possible? The closest I've come is defining the constant in an IDL, then using MIDL and ...
C# and C++ have differing models for constants. Typically, the constant won't even be emitted in the resulting C++ binary -- it's automatically replaced where it is needed most of the time. Rather than using the constant, make a function which returns the constant, which you can P/Invoke from C#. Thus, #include <iostre...
3,146,048
3,146,979
Does this cause a memory leak?
I create my VBO like this: glGenBuffersARB(1,&polyvbo); glBindBufferARB(GL_ARRAY_BUFFER_ARB,polyvbo); glBufferDataARB(GL_ARRAY_BUFFER_ARB,sizeof(GLfloat) * tempvct.size(),&tempvct[0],GL_DYNAMIC_COPY); Then to update it I just do the same thing: glBindBufferARB(GL_ARRAY_BUFFER_ARB,polyvbo); glBufferDat...
It doesn't cause a memory leak because the buffer is not reallocated. But why not use glBufferSubData()? it will probably be much faster and does basically the same thing.
3,146,223
3,146,288
sendmessage does not work
I try to sendmessage to an IE rebar/toolbar, but it seems that my toolbar does not take the message effect. Can someone tell me where is the fault ? HRESULT CButtonDemoBHO::onDocumentComplete(IDispatch *pDisp, VARIANT *vUrl) { m_hWnd = NULL; SHANDLE_PTR nBrowser = NULL; HRESULT hr = m_spWebB...
I would stronly recommned that you check the values of hr and m_hWnd and the return value of sendmessage(). I doubt that "Send message does not work", but am willing to believe "my message does not arrive". Are you sure that you are sending it to a valid destination?
3,146,231
3,146,286
How do I convert an unsigned long array to byte in C++?
How do I convert an unsigned long array to byte in C++? I'm developing using VS2008 C++. Edit: I need to evaluate the size of this converted number,I want to divide this long array to a 29byte array. for example we have long array = 12345; it should convert to byte and then I need its length to divide to 29 and see h...
long array[SOME_SIZE]; char* ptr = reinterpret_cast<char*>( array ); // or just ( char* )array; in C // PC is little-endian platform for ( size_t i = 0; i < SOME_SIZE*sizeof( long ); i++ ) { printf( "%x", ptr[i] ); } Here's more robust solution for you, no endianness (this does not cover weird DSP devices where c...
3,146,344
3,146,629
compatibility of native code C++ and openGL in Windows Phone 7
We have a windows mobile 6.5 gaming application which uses openGL . Now we planned to port it to WP7 (windows phone 7). When I check the compatibility of native code C++ and openGL in WP7, they are telling that there is no support in the WP7. WP7 support only Silverlight, XNA and the .NET Framework. So what we thought...
well I am doing exactly the same thing now. I'm currently going through the painstaking process of just manually converting all the code to c#. there is no little saviour like the Android NDK here with winmo7, you HAVE to use c# if I had my time I would and WILL definitely look into something that converts from c++ t...
3,146,351
3,146,366
C++ getline or cin not accepting a string with spaces, I've searched Google and I'm still stumped!
First of all, thanks to everyone who helps me, it is much appreciated! I am trying to store a string with spaces and special characters intact into MessageToAdd. I am using getline (cin,MessageToAdd); and I have also tried cin >> MessageToAdd;. I am so stumped! When I enter the sample input Test Everything works as ...
I'll tell you one thing that's immediately wrong with your code, not your specific problem but a hairy one nonetheless. I'm presuming that your mainMenu() function is calling this one. In that case, you appear to be under the misapprehension that: if (str == "911") //go back to the main menu { system("cls"); ...
3,146,372
3,162,646
How can I track my input position with multiple inputs using Boost::Spirit::Qi?
I'd like to support something like C++'s #include mechanism in a boost spirit parser. Essentially, I have a script command that asks my parser to load a sub script from a file. I'd like to be able to report error messages as described in the tracking input position while parsing post, but they don't cover parsing for m...
IMHO, using a smart iterator is the way to go. What needs to be done is to have a stack of input contexts maintained by the iterator. Each input context stores the information related to a specific file. Whenever a new file needs to be read (i.e. after seeing an #include statement) a new input context is created. The ...
3,146,438
3,147,859
Should Direct3D be used over OpenGL in Windows?
Since Microsoft is generally a bit bias toward Direct3D, would a scene using VBO's in Direct3D be faster than the same scene using VBO's in OpenGL, or would it be the same since it's up to the Graphics Card driver? Thanks
Performance-wise, and assuming decent GPU drivers, there is no difference overall. Some operations are inherently faster in OpenGL than in DirectX9, although DX10 remedied that. But a good rule of thumb when working with external hardware is that it's not the API you're using that determines performance. When writing n...
3,146,545
3,146,630
how to get country name and/or code by IP address?
Sorry for so noobish question but how can I do it with C++? I need to get country names and their 2-letter or 3-letter ISO codes (or whatever it's called) using a given IP address. Is there any way to do this easily? The only two ways I found are to use GeoIP C library or to download a free database but is there somet...
MaxMind.com exposes a set of web services for geolocation. They're not free, but cheap per lookup. One of my clients uses their city-level lookup service, with each result cached for a reasonable period (from memory, 2 or 3 weeks), since IP address blocks don't change location that often. The application also counts th...
3,146,550
3,146,559
Is there any reason Google uses the cc extension instead of cpp in their open source projects?
Is there any reason Google uses the cc extension instead of the standard cpp in their open source projects? Should I do that too?
It's entirely a matter of personal preference, at least for the person(s) starting the project. Whatever you choose, be consistent.
3,146,628
3,146,688
How to cast wchar_t into int for displaying the code point?
I have a simple function in my program, when I was wanting to mess around with unicode and do stuff with it. In this function, I wished to display the code value of the character the user entered. It SEEMED possible, here's my function: wstring listcode(wchar_t arg) { wstring str = L""; str += static_cast<int> ...
In C++, you cannot add anything to strings but characters and other strings. There is no implicit conversion from int (or anything else) to string. That's just the way the string type is designed. What you do instead is to use string streams: std::wstring listcode(wchar_t arg) { std::wostringstream oss; oss << sta...
3,146,641
3,146,663
How to make a global array with variable number of elements?
Is it posible to declare a global array of a struct, and add elements dynamically to it? Thanks.
If you want to dynamically add elements to something, you might consider using a list. You could create a global list, and dynamically add elements to it as needed. If you really need array type functionality, a vector might be more your speed. In this case, the STL is likely to provide what you need. It's also go...
3,146,675
3,151,067
What is the problem with this simple boost::spirit::qi parser?
I've got this simple parser intended to parse VB style double quoted strings. Thus, the parser should turn something like "This is a quoted string containing quotes ("" "")" into an output of This is a quoted string containing quotes (" ") Here is the grammar I came up with for this: namespace qi = boost::spirit::qi;...
You can do it without any semantic actions: class ConfigurationParser : public qi::grammar<std::wstring::iterator, std::wstring()> { qi::rule<std::wstring::iterator, std::wstring()> quotedString; qi::rule<std::wstring::iterator, wchar_t()> doubleQuote; public: ConfigurationParser() : Configu...
3,146,948
3,154,386
P/Invoke code works on WinXP, exception on Win2k8
I'm attempting to access a function in a DLL in C# and C++. C++ is working fine, as is C# on WinXP. However I'm getting the following error when attempting to access the function on a Win2k8 system: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indi...
I ended up fixing this problem using the details in http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/4e387bb3-6b99-4b9d-91bb-9ec00c47e3a4. I changed the declaration to: [DllImport("Constants.dll", CharSet = CharSet.Unicode)] static extern int GetAddress(StringBuilder strAddress); The usage t...
3,147,014
3,147,048
Is heap memory per-process? (or) Common memory location shared by different processes?
Every process can use heap memory to store and share data within the process. We have a rule in programming whenever we take some space in heap memory, we need to release it once job is done, else it leads to memory leaks. int *pIntPtr = new int; . . . delete pIntPtr; My question: Is heap memory per-process? If YES, ...
On almost every system currently in use, heap memory is per-process. On older systems without protected memory, heap memory was system-wide. (In a nutshell, that's what protected memory does: it makes your heap and stack private to your process.) So in your example code on any modern system, if the process terminates b...
3,147,156
3,147,233
casting comparison between Objective-C and C++
Okay, so this might be a bit of an academic question. Can someone tell me if/how C++'s casting operators might translate to Objective-C... or how/why they're not necessary? I've been out of the loop with C++ for a few years now and it seems like every time I turn around they add a few new keywords. I was recently int...
See this answer to the question When should static_cast, dynamic_cast and reinterpret_cast be used? on the meaning of each kind of casts. what's Objective-C missing that it doesn't seem to have (or need?) this many casting types? C++ focuses a lot more in type safety than C. The many cast operators are added to make ...
3,147,274
3,147,283
C++ Default argument for vector<int>&?
I have a function, void test( vector<int>& vec ); How can I set the default argument for vec ? I have tried void test( vector<int>& vec = vector<int>() ); But there's a warning "nonstandard extension used : 'default argument' : conversion from 'std::vector<_Ty>' to 'std::vector<_Ty> &'" Is there a better way to do ...
Have you tried: void test(const vector<int>& vec = vector<int>()); C++ does not allow temporaries to be bound to non-const references. If you really to need to have a vector<int>& (not a const one), you can declare a static instance and use it as a default (thus non-temporary) value. static vector<int> DEFAULT_VECTOR;...
3,147,359
3,149,750
I am looking for C++ wrapper around built-in Perl functions
A while ago I found a library that allowed calling individual built-in Perl functions in C++, I cannot find it now. Can you tell me where I can find it on the net? Thanks.
You might want to try libperl++. It's still kind of beta, but the part that involves calling perl from C++ has been mature for quite some time. It's much easier to use than the perl API itself. Full disclosure: I'm the author of libperl++
3,147,561
3,147,580
seekg tellg end of line
I have to read lines from an extern text file and need the 1. character of some lines. Is there a function, which can tell me, in which line the pointer is and an other function, which can set the pointer to the begin of line x? I have to jump to lines before and after the current position.
There is no such function i think. You will have to implement this functionality yourself using getline() probably, or scan the file for endline characters (\n) one character at a time and store just the one character after this one. You may find a vector (vector<size_t> probably) helpful to store the offsets of line s...
3,147,754
3,150,286
Python-dependency, windows (CMake)
I have a large, crossplatform, python-dependent project, which is built by CMake. In linux, python is either preinstalled or easily retrived by shell script. But on windows build, i have to install python manually from .msi before running CMake. Is there any good workaround using cmake scripts? PS All other external de...
Python doesn't really have to be installed to function properly. For my own CMake based projects on Windows, I just use a .zip file containing the entire python tree. All you need to do is extract it to a temporary directory, add it to your path, and set your PYTHONHOME/PYTHONPATH environment variables. Once that's don...
3,147,900
3,150,210
How to read file which contains \uxxxx in vc++
I have txt file whose contents are: \u041f\u0435\u0440\u0432\u044b\u0439_\u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439_\u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442_\u043a\u0430\u043d\u0430\u043b How can I read such file to get result like this: "Первый_интерактивный_интернет_кан...
Here is an example for MSalters's suggestion: #include <iostream> #include <string> #include <fstream> #include <algorithm> #include <sstream> #include <iomanip> #include <locale> #include <boost/scoped_array.hpp> #include <boost/regex.hpp> #include <boost/numeric/conversion/cast.hpp> std::wstring convert_unicode_esc...
3,148,081
3,148,155
regenerating connection point methods
I've created a connection point interface _IPlayerEvents. I've added a couple of methods OnConnect() OnDisconnect() I've built the project, and VS2008 has generated code in the CProxy_IPlayerEvents class: HRESULT Fire_OnConnect(){...} HRESULT Fire_OnDisconnect() {...} Now I've added a further method to the _IPlayerEv...
I found an answer! Open Class View in VS2008, right-click your COM object and from its context menu, select Add -> Add Connection Point... Move the source interface from the list on the left over to the right, then click Finish. This will generate or regenerate proxy class when you next build your project. This step ...
3,148,319
3,148,783
Is `volatile` required for shared memory accessed via access function?
[edit] For background reading, and to be clear, this is what I am talking about: Introduction to the volatile keyword When reviewing embedded systems code, one of the most common errors I see is the omission of volatile for thread/interrupt shared data. However my question is whether it is 'safe' not to use volatile w...
My reading of C99 is that unless you specify volatile, how and when the variable is actually accessed is implementation defined. If you specify volatile qualifier then code must work according to the rules of an abstract machine. Relevant parts in the standard are: 6.7.3 Type qualifiers (volatile description) and 5.1.2...
3,148,392
3,148,605
ICC 11.1 has strange behaviour regarding PTHREADS on ia64
I'm working on a ia64-machine using ICC 11.1. The following program compiles nicely: #include <pthread.h> #include <iostream> using namespace std; int main() { cout << PTHREAD_STACK_MIN << '\n'; return 0; } When I compile it with icc test.cpp -o test BUT when I change the contents of the file to to: #include <...
Well, that's easy: you forgot to include <limits.h> where the PTHREAD_STACK_MIN is supposed to be declared (as per POSIXv6/SUSv3). And from the error one can conclude that <iostream> internally also includes the <limits.h> why in C++ mode the error doesn't happen.
3,148,571
3,148,584
Strange class declaration
In Qt's qrect.h I found class declaration starting like this: class Q_CORE_EXPORT QRect { }; As you can see there are two identifiers after class keyword. How shall I understand this? Thank you.
Q_CORE_EXPORT is a macro that gets expanded to different values depending on the context in which it's compiled. A snippet from that source: #ifndef Q_DECL_EXPORT # ifdef Q_OS_WIN # define Q_DECL_EXPORT __declspec(dllexport) # elif defined(QT_VISIBILITY_AVAILABLE) # define Q_DECL_EXPORT __attribute__((visibilit...
3,148,794
3,191,111
c++ boost::serialization setting a fixed class_id for a class
I'mm using boost to serialize and deserialize some classes Like so: boost::archive::xml_oarchive xmlArchive(oStringStream); xmlArchive.register_type(static_cast<BaseMessage *>(NULL)); xmlArchive.register_type(static_cast<IncomingTradeMessage *>(NULL)); xmlArchive.register_type(static_cast<InternalRequestInfo *>(NULL)...
Can't you use BOOST_CLASS_EXPORT_GUID or similar instead? I.e. BOOST_CLASS_EXPORT_GUID(IncomingTradeMessage, "IncomingTradeMessage") ... It will use some more bandwidth since strings are transmitted rather than integers, but it will solve your problem. Refer to this and this for more info. EDIT: This compile just fine...
3,148,850
3,149,059
Is using enum for integer bit oriented operations in C++ reliable/safe?
Consider the following (simplified) code: enum eTestMode { TM_BASIC = 1, // 1 << 0 TM_ADV_1 = 1 << 1, TM_ADV_2 = 1 << 2 }; ... int m_iTestMode; // a "bit field" bool isSet( eTestMode tsm ) { return ( (m_iTestMode & tsm) == tsm ); } void setTestMode( eTestMode tsm ) { ...
I can't see anything bad in that design. However, keep in mind that enum types can hold unspecified values. Depending on who uses your functions, you might want to check first that the value of tsm is a valid enumeration value. Since enums are integer values, one could do something like: eTestMode tsm = static_cast<eTe...
3,148,896
3,149,136
Cryptography libraries conflict (MCrypt, libgcrypt)
I'm trying to perform encryption and decryption (Rijndael 256, ecb mode) in two different components: 1. PHP - Server Side (using mcrypt) 2. C + + - Client Side (using gcrypt) I ran into a problem when the client side could not decrypt correctly the encrypted data (made by the server side) so... i checked the: 1. initi...
OK. I'll make my comment an answer: An Initialization Vector (IV) isn't used in ECB mode. If it is provided different implementations might work differently. If you want to be sure the implementations will work correctly then use an IV of 0 (zero). Even though you provide the IV, both implementations SHOULD ignore it b...
3,148,903
3,149,250
Recursive function returns unexpected result
My funciton takes a number input from the user and recursively sums the number 'n' to one. Inputting a 5 would sum 1/5 + 1/4 + 1/3+ 1/2 + 1/1. #include<stdio.h> #include<conio.h> //to float recursion(float num,float sum); void main(void) { float num=5,sum=0; //input num printf("%d",recursion(num,sum)); getch(...
Why's the printf("%d") while it's supposed to print a float? Doesn't that display an integer making it always 0 for a float less than 0? float recursion(float num) { if( num==1.0f) { printf("1/1 = "); return 1.0f; } float inverse = 1.0f/num; printf("1/%.0f + ", num); return (inve...
3,149,263
3,149,285
Why is there no boost::filesystem::move_file?
I'm using boost filesystem to replace windows C++ functions like CopyFile and MoveFile to get some kind of portability between windows and linux. I'm using copy_file but I have not been able to find anything that moves files like a 'move_file' function. Do boost have a move file function? I would very much prefer to us...
It's called rename, see the manual. Like the corresponding OS functions, this might or might not work if the source and destination paths are on different file systems. If it doesn't work, use a copy operation followed by a delete operation.