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 |
|---|---|---|---|---|
1,065,672 | 1,065,729 | How to link against boost.system with cmake | I use a cmake generated makefile to compile a c++ file that depends on the boost filesystem library.
During the linking process I get the following error:
Undefined symbols:
"boost::system::get_generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in FaceRecognizer.cpp.o
... | On linux CMake figures itself that boost_filesystem is linked against boost_system. Obviously you have to tell it explicitly on Mac:
find_package(Boost COMPONENTS system filesystem REQUIRED)
#...
target_link_libraries(mytarget
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
)
|
1,065,743 | 1,065,830 | Using Boost::asio in Winx64: I'm stuck, need to figure out how to build libboost_system_xxxx.lib for x64 | Unlike this question:
Linker Error while building application using Boost Asio in Visual Studio C++ 2008 Express
I need an x64 build of the lib files... I'm not even sure how to get started. I'm reading here:
http://www.boost.org/doc/libs/1_39_0/more/getting_started/windows.html
Or, more generally, how do I build boost... | I'm not on Windows, but I guess adding address-model=64 to the bjam invocation should do the trick.
|
1,065,774 | 1,065,800 | Initialization of all elements of an array to one default value in C++? | C++ Notes: Array Initialization has a nice list over initialization of arrays. I have a
int array[100] = {-1};
expecting it to be full with -1's but its not, only first value is and the rest are 0's mixed with random values.
The code
int array[100] = {0};
works just fine and sets each element to 0.
What am I missing ... | Using the syntax that you used,
int array[100] = {-1};
says "set the first element to -1 and the rest to 0" since all omitted elements are set to 0.
In C++, to set them all to -1, you can use something like std::fill_n (from <algorithm>):
std::fill_n(array, 100, -1);
In portable C, you have to roll your own loop. The... |
1,066,071 | 1,067,072 | Boost linker error: Unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::get_system_category(void)" | I'm just getting started with Boost for the first time, details:
I'm using Visual Studio 2008 SP1
I'm doing an x64 Build
I'm using boost::asio only (and any dependencies it has)
My code now compiles, and I pointed my project at the boost libraries (after having built x64 libs) and got past simple issues, now I am fac... | I solved the problem. I had built 32-bit libraries when I had intended to build 64-bit libraries. I fixed up my build statement, and built 64-bit libraries, and now it works.
Here is my bjam command line:
C:\Program Files (x86)\boost\boost_1_38>bjam --build-dir=c:\boost --build-type=complete --toolset=msvc-9.0 address-... |
1,066,137 | 1,066,200 | What is the Preferred Cross-platform 'main' Definition Using boost::program_options? | I'm trying to develop a cross-platform application using C++ with boost.
I typically program in a *nix environment, where I've always defined 'main' as follows:
int main( const int argc, const char* argv[] )
{
...
}
For this application, I'm starting in the Windows environment, using Visual Studio 2003.
When I try to... | It seems to be a constness related problem. Try:
int main( int argc, char* argv[] )
{
// ...
}
|
1,066,183 | 1,086,771 | QWinWidget Inside MFC Dialog Not Repainting or Responding to Tab/Arrow keys | I am using a QWinWidget inside of an MFC dialog and the QWinWidget is not drawing itself correctly and it is not handling keyboard input correctly.
Repainting [Unsolved]
Within the QWinWidget, I have a QTableWidget. When I scroll the QTableWidget, it does not redraw itself until I stop scrolling, at which point it redr... | I have fixed the keyboard input issue. The QWinWidget class needed some changes:
in the QWinWidget::init method, the WS_TABSTOP must be added to the window style:
SetWindowLong(winId(), GWL_STYLE, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP);
Also, the QWinWidget::winEvent method needs to respond to the ... |
1,066,677 | 1,066,706 | How to iterate over a std::map full of strings in C++ | I have the following issue related to iterating over an associative array of strings defined using std::map.
-- snip --
class something
{
//...
private:
std::map<std::string, std::string> table;
//...
}
In the constructor I populate table with pairs of string keys associated to string data. Somewhere else I ... | Your main problem is that you are calling a method called first() in the iterator. What you are meant to do is use the property called first:
...append(iter->first) rather than ...append(iter->first())
As a matter of style, you shouldn't be using new to create that string.
std::string something::toString()
{
... |
1,066,971 | 1,066,979 | Is C or C++ better for making portable code? | I am trying to have some fun in summer. Writing a piece of code that enables presenting Arabic language in systems that support Unicode but no support for eastern languages it. I am writing only the logic hopefully with no integration code initially.
Should I use C++ or C?
Which is the easier language to write portable... | I would use C++, mostly because it provides a lot more "stuff" to use and as far as my experience goes is as portable as C. However, I have not used straight C/C compiler for 10 years or more.
EDIT
A commenter questioned my experience with portability. Mine is limited to Linux and Win32 primarily. I assumed this would... |
1,067,066 | 1,067,079 | Compilation errors through incorrect use of CComPtr objects | I have defined the following CComPtr object and method in my class:
private:
CComPtr<IRawPdu>& getRawPdu();
// Returns the RawPdu interface pointer from the mRawPdu data member.
// mRawPdu is initialized, if necessary.
CComPtr<IRawPdu> mRawPdu;
// Initialized to 0 in the ctor. Uses lazy evaluatio... | Based on the error given by the compiler it appears that it cannot infer a conversion between IRawPdu and IUnknown.
Does it actually inherit from IUnknown? If so then it's possibly an include ordering issue. Can you give more insight into the hierarchy of IRawPdu
|
1,067,102 | 1,154,402 | C++ XML comments to generate MSDN style CHM | I have several projects, some using managed code and some using only unmanaged. All have the XML comments have been added and the XML documentation is being generated correctly (the generated xml file and intermediate the xdc files).
Surely there's something that can take these files (the output of xdcmake) and generat... | You might want to try DoxyComment. Here is the description from Doxygen's Helper tools & scripts:
An addin for Visual Studio 2005 called
DoxyComment was created by Troels
Gram. It is designed to assist you in
inserting context sensitive comment
blocks into C/C++ source files.
DoxyComment also comes with an x... |
1,067,236 | 1,067,249 | C/C++ testing framework (like JUnit for java) | Been hitting my head on the wall before as I don't make any test classes while using c/c++ (but instead have a lot of print methods).
What is the most used method to perform testing in the c/c++ code? Java's JUnit has only left me with good memories while debugging things.
I know that using asserts in code with a defi... | You can check these out:
http://gamesfromwithin.com/?p=29
http://www.opensourcetesting.org/unit_c.php
http://msdn.microsoft.com/en-us/magazine/cc136757.aspx
|
1,067,346 | 1,067,684 | Alternatives to dlsym() and dlopen() in C++ | I have an application a part of which uses shared libraries. These libraries are linked at compile time.
At Runtime the loader expects the shared object to be in the LD_LIBRARY_PATH , if not found the entire application crashes with error "unable to load shared libraries".Note that there is no guarantee that client w... | The common solution to your problem is to declare a table of function pointers, to do a single dlsym() to find it, and then call all the other functions through a pointer to that table. Example (untested):
// libfoo.h
struct APIs {
void (*api1)(void);
void *(*api2)(int);
long (*api3)(int, void *);
};
// lib... |
1,067,535 | 1,067,561 | Custom-typed Reference members in C++ - initialising them | this snippet of code is given me headache. Personally, I would like to use reference as they are neater compared to pointer, so I tried this:
include "SomeClass.h"
class FooBar
{
private:
SomeClass& member_;
public:
FooBar() : member_(SomeClass()) { };
}
I have read that you need to assign a temp va... | 1) References can not be changed to point to another object after it is initialized.
Do you really need this behavior?
2) When you initialize reference with temporary object, after this temp. object is out of scope your reference is invalid.
That's why your code is incorrect. And you have useless member now. I'd recomm... |
1,067,558 | 1,067,622 | Pass an unary predicate to a function in C++ | I need a function which establishes a policy for my class for displaying items. e.g:
SetDisplayPolicy(BOOLEAN_PRED_T f)
This is assuming BOOLEAN_PRED_T is a function-pointer to some boolean predicate type like:
typedef bool (*BOOLEAN_PRED_T) (int);
I'm interested only on e.g: display something when the passed predica... | Turn SetDisplayPolicy into a function template:
template<typename Pred>
void SetDisplayPolicy(Pred &pred)
{
// Depending on what you want exactly, you may want to set a pointer to pred,
// or copy it, etc. You may need to templetize the appropriate field for
// this.
}
Then to use, do:
struct MyPredClass
{
... |
1,067,607 | 1,067,661 | Closing a thread with select() system call statement? | I have a thread to monitor serial port using select system call, the run function of the thread is as follows:
void <ProtocolClass>::run()
{
int fd = mPort->GetFileDescriptor();
fd_set readfs;
int maxfd=fd+1;
int res;
struct timeval Timeout;
Timeout.tv_usec=0;
Timeout.tv_sec=3;
//BYTE ... | I'm not sure what threading library you use, but you should probably signal the thread in one way or another that it should exit, rather than killing it.
The most simple way would be to keep a boolean that is set true when the thread should exit, and use a timeout on the select() call to check it periodically.
Protocol... |
1,067,630 | 1,067,819 | SSE2 option in Visual C++ (x64) | I've added x64 configuration to my C++ project to compile 64-bit version of my app. Everything looks fine, but compiler gives the following warning:
`cl : Command line warning D9002 : ignoring unknown option '/arch:SSE2'`
Is there SSE2 optimization really not available for 64-bit projects?
| Seems to be all 64-bit processors has SSE2. Since compiler option always switched on by default no need to switch it on manually.
From Wikipedia:
SSE instructions: The original AMD64 architecture adopted Intel's SSE and SSE2 as core instructions. SSE3 instructions were added in April 2005. SSE2 replaces the x87 instru... |
1,067,821 | 1,068,111 | ublas vs. matrix template library (MTL4) | I'm writing a software for hyperbolic partial differential equations in c++. Almost all notations are vector and matrix ones. On top of that, I need the linear algebra solver. And yes, the vector's and matrix's sizes can vary considerably (from say 1000 to sizes that can be solved only by distributed memory computing, ... | With your requirements, I would probably go for BOOST::uBLAS. Indeed, a good deployment of uBLAS should be roughly on par with MTL4 regarding speed.
The reason is that there exist bindings for ATLAS (hence shared-memory parallelization that you can efficiently optimize for your computer), and also vendor-tuned implemen... |
1,067,827 | 1,067,862 | Dangerous ways of removing compiler warnings? | I like to force a policy of no warnings when I check someone's code. Any warnings that appear have to be explicitly documented as sometimes it's not easy to remove some warnings or might require too many cycles or memory etc.
But there is a down-side to this policy and that is removing warnings in ways that are potenti... | const correctness can cause a few problems for beginners:
// following should have been declared as f(const int & x)
void f( int & x ) {
...
}
later:
// n is only used to pass the parameter "4"
int n = 4;
// really wanted to say f(4)
f( n );
Edit1: In a somewhat similar vein, marking all member variables as mutable... |
1,067,986 | 1,070,240 | C++ Linking and COM Registration issue | I've added a new library to my application (multiple projects-DLLs) - SQLite, to perform some in memory caching. There is just one library/project that is affected by this change - Lib1.
A build goes through fine. All libraries are built successfully and no errors are reported, including a couple of Com Objects.
If I t... | You can use Process Monitor (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) set to filter process name regsvr32.exe in order to see all file and registry access.
Always use full path to your-com-dll when you issue regsvr32 commands, if you have the same dll somewhere else in path (for example c:\windows... |
1,068,092 | 1,068,136 | Exposing C# via COM for C++ Client | we're considering exposing some C# types to C++ clients via COM. What problems can we expect to hit over the life of the project? E.g. how will versioning be managed?
On versioning, it would seem from reading this that we should decorate our types to be exposed with [ClassInterface(ClassInterfaceType.None)] and use a... | Since you are using a C++ client you should definitely use explicit interfaces for early binding. Dispatch interfaces are useful when using scripting clients such as VBS but they are rarely useful for C++ clients.
The only way to version an interface is to create a new interface (possibly inheriting from the original ... |
1,068,134 | 1,068,240 | Comparing wstring with ignoring the case | I am sure this would have been asked before but couldn't find it. Is there any built in (i.e. either using std::wstring's methods or the algorithms) way to case insensitive comparison the two wstring objects?
| If you don't mind being tied to Microsoft implementation you can use this function defined in <string.h>
int _wcsnicmp(
const wchar_t *string1,
const wchar_t *string2,
size_t count
);
But if you want best performance/compatibility/functionality ratio you will probably have to look at boost library (part of i... |
1,068,557 | 1,069,200 | C++ Storing references to values in std::map | Am I right in assuming that adding/removing elements to an std::map does not effect the other elements (ie cause them to be relocated in memory) and so that the following is safe:
I looked at various sites with info on the container but only found out about the cases where iterators are invalidated, which I already kno... | The Standard is clear on this in 23.1.2/8 about associative containers
The insert members shall not affect the validity of iterators and references to the container, and the erase members shall invalidate only iterators and references to the erased elements.
|
1,068,663 | 1,077,548 | How to modify options being passed to ld , without recompiling gcc | I'm trying to compile shared library on solaris 2.7 using gcc 3.4.6 and
which is linking to a statically linked c .a and .o files.
Please note that it is using Sun ld from path "/usr/ccs/bin/ld"
At linking time i got a long list of symbols and following error
ld: fatal: relocations remain against allocatable but non-... | The errors are the result of linking position-dependent code into a shared library. Such code will result in the library not being shareable, and thus wasting RAM.
If you can rebuild all the objects you are trying to link into the shared library, the simplest (and most correct) solution is to rebuild all of them with -... |
1,068,762 | 1,068,797 | Calling C# from C++, Reverse P/Invoke, Mixed Mode DLLs and C++/CLI | As I understand it I can use reverse P/Invoke to call C# from C++. Reverse P/Invoke is simply a case of:
Create you managed (c#) class.
Create a c++/cli (formerly managed c++) class library project. Use this to call the managed c# class (presumably via a reference).
Call the c++/cli code from native c++.
Questions:... | Here are the answers to the best of my knowledge:
Yes
Yes, it is a mixed mode DLL (In fact, you can make one file of your native C++ project managed and create this C++/CLI class in that file and call the code directly from that file. You don't even need a separate DLL to accomplish this.
C++/CLI and Managed C++ both ... |
1,069,335 | 1,069,367 | How to implement 'virtual ostream & print( ostream & out ) const;' | I found this function in the header file of an abstract class:
virtual ostream & print( ostream & out ) const;
Can anyone tell me what kind of function this is and how to declare it in a derived class?
From what I can tell, it looks like it returns a reference to an outstream.
If I implement it in my cc file with noth... | some implementation:
ostream& ClassA::print( ostream& out) const
{
out << myMember1 << myMember2;
return out;
}
Returning the same ostream allows combinations like
a.print( myStream) << someOtherVariables;
However, it is still strange to use it this way.
Regarding the error, ostream is part of std namespace, ... |
1,069,352 | 1,069,397 | Is it possible to turn off support for "and" / "or" boolean operator usage in gcc? | GCC seems to allow "and" / "or" to be used instead of "&&" / "||" in C++ code; however, as I expected, many compilers (notably MSVC 7) do not support this. The fact that GCC allows this has caused some annoyances for us in that we have different developers working on the same code base on multiple platforms and occasio... | They are part of the C++ standard, see for instance this StackOverflow answer (which quotes the relevant parts of the standard).
Another answer in the same question mentions how to do the opposite: make them work in MSVC.
To disable them in GCC, use -fno-operator-names. Note that, by doing so, you are in fact switching... |
1,069,525 | 1,070,045 | How to convert Win Mobile 6 project into Win CE 6.0 RC2 | I have a Windows Mobile 6 Professional native project that runs ok on Win Mobile devices. Now I need a version that runs on Windows Embedded CE 6.0 RC2. What is the best path for this conversion? Can I just change few project settings / add new platform with configuration manager OR I have to start with new smart devic... | Adding a new configuration to a native platform is, and always has been, a real nightmare. Your best bet is to just create a new project and add in the source files again. I've complained about this to the Studio for Devices team several times, but it doesn't seem to be a priority to fix.
Bear in mind that if you use... |
1,069,602 | 1,656,679 | How do I install a c++ library so I can use it? | I have this library called BASS which is an audio library which I'm going to use to record with the microphone. I have all the files needed to use it, but I don't know how to install the library. I tried taking the example files and putting them in the same directory as the bass.h file. But I got a bunch of errors sayi... | Installing a C++ library means specifying to interested software (eg. a compiler) the location of two kinds of files: headers (typical extensions *.h or .hpp) and compiled objects (.dll or *.lib for instance).
The headers will contain the declarations exposed to the developer by the library authors, and your program wi... |
1,069,621 | 1,069,634 | Are members of a C++ struct initialized to 0 by default? | I have this struct:
struct Snapshot
{
double x;
int y;
};
I want x and y to be 0. Will they be 0 by default or do I have to do:
Snapshot s = {0,0};
What are the other ways to zero out the structure?
| They are not null if you don't initialize the struct.
Snapshot s; // receives no initialization
Snapshot s = {}; // value initializes all members
The second will make all members zero, the first leaves them at unspecified values. Note that it is recursive:
struct Parent { Snapshot s; };
Parent p; // receives no initi... |
1,069,860 | 1,069,888 | OpenThread() Returns NULL Win32 | I feel like there is an obvious answer to this, but it's been eluding me. I've got some legacy code in C++ here that breaks when it tries to call OpenThread(). I'm running it in Visual C++ 2008 Express Edition. The program first gets the ThreadID of the calling thread, and attempts to open it, like so:
ThreadId thr... | Maybe you're asking for too much access (THREAD_ALL_ACCESS), though I'd think that you'd have pretty much all permissions to your own thread. Try reducing the access to what you really need.
What does GetLastError() return?
Update:
Take a look at this comment from MSDN:
Windows Server 2003 and Windows
XP/2000: The... |
1,070,333 | 1,074,325 | Is there an easier way to pop off a directory from boost::filesystem::path? | I have a relative path (e.g. "foo/bar/baz/quux.xml") and I want to pop a directory off so that I will have the subdirectory + file (e.g. "bar/baz/quux.xml").
You can do this with path iterators, but I was hoping there was something I was missing from the documentation or something more elegant. Below is the code that ... | Here is something that a co-worker figured out just using string::find with boost::filesystem::slash. I like this that it doesn't require iterate over the entire path breaking it up, but also using the path's OS-independent definition of the path separation character. Thanks Bodgan!
boost::filesystem::path pop_front_... |
1,070,351 | 1,070,481 | GetAdaptersInfo and GetAdaptersAddressess BufferLength Param | I've got some legacy code in C++ here that does some things I don't understand. I'm running it in Visual C++ 2008 Express Edition on a machine running Windows XP.
The code uses some Windows functions: GetAdaptersInfo and GetAdaptersAddressess. I realize that the final parameter for both of these is a pointer to the si... | Your code needs to look something like this:
// First get the desired size.
unsigned long outBufLen = 0;
DWORD dwResult = GetAdaptersInfo(NULL, &outBufLen);
if (dwResult == ERROR_BUFFER_OVERFLOW) // This is what we're expecting
{
// Now allocate a structure of the requried size.
PIP_ADAPTER_INFO pIpAdapterInfo... |
1,070,363 | 1,070,457 | Generate HTML Pages from C Structures | I would like to develop a application (i prefer c++), which will take C header file with lot of nested structures as input and generate a html page where the data will be presented as Hierarchial tree structures, which can be collapsed..
file.h
struct level1
{
struct level2
{
struct level3
{
}
}
}... | The hardest part will be parsing the C header files. GCCXML will do that for you, outputting an XML structure that's then trivial to parse.
|
1,070,497 | 1,070,499 | C++ convert hex string to signed integer | I want to convert a hex string to a 32 bit signed integer in C++.
So, for example, I have the hex string "fffefffe". The binary representation of this is 11111111111111101111111111111110. The signed integer representation of this is: -65538.
How do I do this conversion in C++? This also needs to work for non-neg... | use std::stringstream
unsigned int x;
std::stringstream ss;
ss << std::hex << "fffefffe";
ss >> x;
the following example produces -65538 as its result:
#include <sstream>
#include <iostream>
int main() {
unsigned int x;
std::stringstream ss;
ss << std::hex << "fffefffe";
ss >> x;
// output i... |
1,070,666 | 1,070,824 | Eclipse c++ makefile project output | I have a c++ Makefileproject for eclipse, if I build it, the binary is in the project root. How can I change the build directory to {ROOT}/bin?
I Tryed project propertys -> c/c++ Build -> Build location (Build directory: MY PATH)
but than it can't compile at all.
| You use a Makefile-Project. Everything that has to be done, including where to put an executable, has to be coded into the Makefile by you! Eclipse just kicks the build by invoking make.
An simple example:
CXXFLAGS= -g -O0
CXX=g++
all: bin bin/test
bin/test: bin/test.o
$(CXX) -o bin/test bin/test.o
bin/test.o... |
1,070,813 | 1,070,890 | Setup main function in eclipse makefile project | I created a new HalloWorld Makefile Project. There is a HalloWorld.cpp with my main function.
Now I have a file /src/startup.cpp that conains a main function. Now I want to use the main function from /src/startup.cpp
Where can I tell eclipse to use that one?
| Place the following in the file Makefile at the project root
CXXFLAGS= -g -O0
CXX=g++
all: bin bin/myprog
bin/myprog: bin/startup.o
$(CXX) -o bin/myprog bin/startup.o
bin/startup.o: src/startup.cpp
$(CXX) $(CXXFLAGS) -o bin/startup.o -c src/startup.cpp
bin:
mkdir bin
clean:
rm bin/startup.o
rm ... |
1,070,882 | 1,070,897 | C++ string.compare() | I'm building a comparator for an assignment, and I'm pulling my hair out because this seems to simple, but I can't figure it out.
This function is giving me trouble:
int compare(Word *a, Word *b)
{
string *aTerm = a->getString();
string *bTerm = b->getString();
return aTerm->compare(bTerm);
}
Word::getStr... | You're comparing a string to a string pointer, and that's not valid. You want
return aTerm->compare(*bTerm);
|
1,071,092 | 1,071,111 | What are the uses of pure virtual functions in C++? | I'm learning about C++ in a class right now and I don't quite grok pure virtual functions. I understand that they are later outlined in a derived class, but why would you want to declare it as equal to 0 if you are just going to define it in the derived class?
| Briefly, it's to make the class abstract, so that it can't be instantiated, but a child class can override the pure virtual methods to form a concrete class. This is a good way to define an interface in C++.
|
1,071,119 | 1,071,461 | Accessing types from dependent base classes | Does anyone know why using-declarations don't seem to work for importing type names from dependent base classes? They work for member variables and functions, but at least in GCC 4.3, they seem to be ignored for types.
template <class T>
struct Base
{
typedef T value_type;
};
template <class T>
struct Derived : Base... | As Richard Corden points out, this issue was addressed in the C++ Standard Core Language Defect Reports after the 2003 standard was ratified: How do the keywords typename/template interact with using-declarations?
Proposed resolution (April 2003,
revised October 2003):
Add a new paragraph to the bottom of
7.3.3 [n... |
1,071,120 | 1,071,745 | How do I use MySQL C++ Connector for storing binary data? | I have a block of binary data defined as:
void* address, size_t binarySize;
that I want to store to a MySQL database using MySQL C++ Connector.
The function setBlob() takes istream.
The question:
How can I convert from a raw void* address, size_t binarySize to either an istream object or istringstream? Is it possible t... | You have to subclass streambuf e.g. like this:
class DataBuf : public streambuf
{
public:
DataBuf(char * d, size_t s) {
setg(d, d, d + s);
}
};
Then you can instantiate an istream object which uses a DataBuf as buffer, which itself uses your block of binary data. Supposing that binarySize specifies the siz... |
1,071,417 | 1,071,598 | can't seem to build a Qt project on eclipse (C++, Windows) | I have Qt installed + Qt Eclipse Integration + MinGW but I can't seem to find a way to build a new Qt GUI project.
I'm getting the following error:
Error launching builder (mingw32-make debug )
(Cannot run program "mingw32-make": Launching failed)
I've updated the Path variable and added all I can think about that can ... | When installing mingw, have you selected the checkbox to install mingw's make too?
You could have a look into c:\mingw\bin and see if there is a mingw32-make executable and you could try to launch mingw32-make from a windows console. Probably there is something wrong with your mingw installation.
Hope that helps,
Elroh... |
1,071,606 | 1,071,770 | How to read "Contributing Artist" metadata in C++? | Windows 7 has a very nifty way of showing "Contributing Artist" metadata in Windows Explorer. In wonder how can I access that metadata from C++? Maybe you even point to some source code? Greatly appreciate in advance.
| Assuming you can limit your app to Windows Vista and later, use IPropertyStore. Otherwise each file type needs to be parsed independently.
|
1,071,674 | 1,071,718 | Dynamically allocated arrays or std::vector | I'm trying to optimize my C++ code. I've searched the internet on using dynamically allocated C++ arrays vs using std::vector and have generally seen a recommendation in favor of std::vector and that the difference in performance between the two is negligible. For instance here - Using arrays or std::vectors in C++, wh... | When benchmarking C++ comtainers, it's important to enable most compiler optimisations. Several of my own answers on SO have fallen foul of this - for example, the function call overhead when something like operator[] is not inlined can be very significant.
|
1,071,720 | 1,071,859 | SQL-Like Selects in Imperative Languages | I'm doing some coding at work in C++, and a lot of the things that I work on involve analyzing sets of data. Very often I need to select some elements from a STL container, and very frequently I wrote code like this:
using std::vector;
vector< int > numbers;
for ( int i = -10; i <= 10; ++i ) {
numbers.push_back( i ... | LINQ is the obvious answer for .NET (or Mono on non-Windows platforms, but in C++, it shouldn't be that difficult to write something like it yourself in STL.
Use the Boost.Iterator library to write a "select" iterator, for example, one which skips all elements that do not satisfy a given predicate.
Boost already has a ... |
1,071,778 | 1,074,038 | Data streaming in MATLAB with input data coming in from a C++ executable | I'm completely new to MATLAB and I want to know what my options are for data streaming from a C++ file.
I heard of using the MATLAB "engine" for this purpose, and some of the methods like engPutVariable, etc., but can someone give me a thorough example of how to go about doing it? I'm trying to implement streaming a si... | You have two options: the matlab engine and mex functions. It's very important to note that the Matlab API is single-threaded. There is absolutely no way to have user-visible background threads. At best, there are interrupts for UI events.
With the Matlab engine, your application is a C++ application that uses Matla... |
1,071,804 | 1,071,926 | yyparse is printing a leading tab | In my bison/flex program, right after yyparse() is called, a leading tab is printed, but I don't know why. Can you see what's wrong?
This calls the bison code, and right after yyparse() returns, a tab is printed.
void parseArguments(int argc, char** argv)
130 {
131 int i;
132
133 int sum = 0;
134 // calcul... | Is the tab not handled in you lexer and therefore the default rule matching and echoed is being applied?
Put a extra match
\t { printf("TAB"); }
into the code before your end code section.
if that shows TAB instead of the \t, then turn the printf into an empty statement
\t { /*printf("TAB")*/; }
After lex posting E... |
1,071,888 | 1,071,897 | Can I make C++ in Visual Studio 2008 behave like an earlier version? | I need to work with some old C++ code that was developed in Visual C++ 6.0. Right now it's giving me compile errors galore. (For instance, "cannot open include file: 'iostream.h'"... because now it should say #include <iostream> rather than #include <iostream.h>).
How can I work with this code without having to chang... | Unfortunately, there isn't a targetting feature in VS2008 that lets you do this.
You'll just need to clean up your code. Luckily, VS2008 is far more standards-compliant than older versions of Visual C++ (in particular, VC 6). Getting the code clean should help in the future (you're less likely to have to worry about ... |
1,072,085 | 1,286,193 | Control Click to get definition in IDE does not work | I am using C++Builder, I know that to go to a definition of a variable or class you must press control and click on the method name, or any identifier where you want to go to a definition.
However, as most of you would notice this does not work all the time.
Does anyone have any trick on doing this?
| I actually used the Visual Studio Emulator for keys and because of that I can now right click a popup menu and go to definition.
Another benefit of enumlating the Visual Studio keyboard setup is the multiple line tab and alt-Tab now works. Sadly no more shortcut to compile (F6 for RAD Studio 2007 default keyboard setup... |
1,072,099 | 1,072,123 | Visual Studio 2008, error c2039: 'set_new_handler' : is not a member of 'std' | So the other day I went to compile a VC++ project I am working on and all of a sudden I get errors in almost all of my files saying:
new.h: error C2039: 'set_new_handler' : is not a member of 'std
new.h: error C2039: 'set_new_handelr' : symbol cannot be used in a using-declaration
"new.h" and 'set_new_handler' are ... | If I were to hazard a guess, I would say that <new.h> declares set_new_handler in the global namespace and <new> declares it within the std namespace. Some code is including <new.h> and expecting it to act as if it had included <new>. I would suspect either some 3rd party library/header or a precompiled header as sugge... |
1,072,484 | 1,072,524 | Fast string matching algorithm with simple wildcards support | I need to match input strings (URLs) against a large set (anywhere from 1k-250k) of string rules with simple wildcard support.
Requirements for wildcard support are as follows:
Wildcard (*) can only substitute a "part" of a URL. That is fragments of a domain, path, and parameters. For example, "*.part.part/*/part?part=... | If I'm not mistaken, you can take string rule and break it up into domain, path, and query pieces, just like it's a URL. Then you can apply a standard wildcard matching algorithm with each of those pieces against the corresponding pieces from the URLs you want to test against. If all of the pieces match, the rule is a ... |
1,073,384 | 1,073,434 | What strategies have you used to improve build times on large projects? | I once worked on a C++ project that took about an hour and a half for a full rebuild. Small edit, build, test cycles took about 5 to 10 minutes. It was an unproductive nightmare.
What is the worst build times you ever had to handle?
What strategies have you used to improve build times on large projects?
Update:
How mu... |
Forward declaration
pimpl idiom
Precompiled headers
Parallel compilation (e.g. MPCL add-in for Visual Studio).
Distributed compilation (e.g. Incredibuild for Visual Studio).
Incremental build
Split build in several "projects" so not compile all the code if not needed.
[Later Edit]
8. Buy faster machines.
|
1,073,543 | 1,388,914 | Qt Creator source files | Is it possible to set up QtCreator to treat .d files as C sources?
| There is a file called CppEditor.mimetypes.xml embedded as a resource in the binary executable. This file contains a list of file extensions that are treated as C++ source files.
It can be found in the source tree here:
src/plugins/cppeditor/CppEditor.mimetypes.xml
I don't think you can change the list without recompil... |
1,073,754 | 1,073,767 | Linker Error on having non Inline Function defined in header file? | Non inline function defined in header file with guards
#if !defined(HEADER_RANDOM_H)
#define HEADER_RANDOM_H
void foo()
{
//something
}
#endif
Results in linker error : Already defined in someother.obj file
Making the function inline works fine but I am not able to understand why the function is already erroring out... | If the header is included in more than one source file and the function is not marked as "inline" you will have more than one definition. The include guards only prevent multiple inclusions in the same source file.
|
1,073,958 | 1,074,030 | Extending the C++ Standard Library by inheritance? | It is a commonly held belief that the the C++ Standard library is not generally intended to be extended using inheritance. Certainly, I (and others) have criticised people who suggest deriving from classes such as std::vector. However, this question: c++ exceptions, can what() be NULL? made me realise that there is at ... | Good nice question. I really wish that the Standard was a little more explicit about what the intended usage is. Maybe there should be a C++ Rationale document that sits alongside the language standard. In any case, here is the approach that I use:
(a) I'm not aware of the existence of any such list. Instead, I use the... |
1,074,130 | 1,074,151 | How do I avoid compiler warnings when converting enum values to integer ones? | I created a class CMyClass whose CTor takes a UCHAR as argument. That argument can have the values of various enums (all guaranteed to fit into a UCHAR). I need to convert these values to UCHAR because of a library function demanding its parameter as that type.
I have to create a lot of those message objects and to sav... | I wouldn't be emabarrassed by static_cast here, but if you are:
template <class T>
inline UCHAR ToUchar(T t)
{
return static_cast<UCHAR>(t);
}
saves writing a function for every enum.
|
1,074,247 | 1,074,319 | Error c2061 when compiling | When I compile a project I get this error:
C:\DATOSA~1\FAXENG~1>nmake /f
Makefile.vc clean
Microsoft (R) Program Maintenance
Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation.
All rights reserved.
cd src
nmake /nologo /f Makefile.vc clean
del /F *.obj *.lib *.dll *.exe *.res *.exp... |
FaxAPI.cpp(143) : error C2061: syntax
error : identifier 'CClassZero'
The error is at or near line number 143, in file FaxAPI.cpp.
The error is related to the identifier CClassZero
(Possibly being undefined, or misused. Possibly something as mundane as a missing semicolon).
If you cannot find the error in FaxAPI.cpp... |
1,074,362 | 1,074,911 | Embedded resource in C++ | How do I create an embedded resource and then access it from C++?
Any example on how to read the resource would be great.
I am using Visual Studio 2005.
Thanks in advance.
Edit: I want to put one xsd file which is required while validating schema of the recieved xml file.
| I'm doing @Sharptooth explained before and use the following code to get the resource
HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(resourceId), type);
HGLOBAL hRes = LoadResource(hInstance, hResInfo);
LPVOID memRes = LockResource(hRes);
DWORD sizeRes = SizeofResource(hInstance, hResInfo);
Here you have to ... |
1,074,428 | 1,074,720 | How to write to a varchar(max) column using ODBC | Summary: I'm trying to write a text string to a column of type varchar(max) using ODBC and SQL Server 2005. It fails if the length of the string is greater than 8000. Help!
I have some C++ code that uses ODBC (SQL Native Client) to write a text string to a table. If I change the column from, say, varchar(100) to varcha... | You sure you load the SQL Native Driver for 2005, not the old driver for 2000? The native driver name is {SQL Server Native Client 10.0} for 2k8 or {SQL Native Client} for 2k5
The error message ODBC SQL Server Driver seem to indicate the old 2k driver (I may be wrong, haven't touch ODBC in like 10 years now).
|
1,074,474 | 1,074,537 | Should I use double or float? | What are the advantages and disadvantages of using one instead of the other in C++?
| If you want to know the true answer, you should read What Every Computer Scientist Should Know About Floating-Point Arithmetic.
In short, although double allows for higher precision in its representation, for certain calculations it would produce larger errors. The "right" choice is: use as much precision as you need ... |
1,075,154 | 1,075,191 | memory allocation in C++ | Is it possible to allocate an arbitrary memory block using the "new" operator?
In C I can do it like "void * p = malloc(7);" - this will allocate 7 bytes if memory alignment is set to 1 byte. How to make the same in C++ with the new operator?
| Arbitrary memory blocks can be allocated with operator new in C++; not with the new operator which is for constructing objects.
void* pBlock = ::operator new(7);
Such blocks can subsequently be freed with operator delete.
::operator delete(pBlock);
Note that operator new will allocated memory suitably aligned for any... |
1,075,243 | 1,075,261 | Get Last Error from LogonUser function and return it as a String? | I am just wondering how i can get the error causing LoginUser function to fail in my C++ program and return it as a String?
JNIEXPORT jstring JNICALL Java_com_entrust_adminservices_urs_examples_authn_LdapAuthenticator2_takeInfo(JNIEnv *env, jobject obj, jstring domain, jstring id, jstring idca, jstring password)
{
... | In Windows, you can use GetLastError to retrieve the error, and then FormatMessage to turn that into a string you can use.
|
1,075,614 | 1,075,709 | using copy with multi-dimensional arrays | I'm just trying to get more into stl semantics, and converting old loops over to algorithms where appropriate. I'm having trouble figuring out the best way to transform this loop into a call to copy. Any ideas?
vector< vector<float> > rvec;
const float * r[Max] = ...;
// ...
for (int ri=0; ri<N; ri+... | rvec.resize(Max);
for (int i = 0; i < Max; ++i) {
rvec[i].resize(M);
std::copy(r[i], r[i] + M, rvec[i].begin());
}
If rvec itself and each vector in rvec already has the correct size, then resizing isn't needed.
|
1,075,712 | 1,075,785 | Reading delimited files in C++ | What is the best way to read in a tab delimited file in C++ and store each line as a record? I have been looking for an open source library to help with this, but have been unsuccessful so it looks like I will have to write my own.
| typedef vector<vector<string> > Rows;
Rows rows;
ifstream input("filename.csv");
char const row_delim = '\n';
char const field_delim = '\t';
for (string row; getline(input, row, row_delim); ) {
rows.push_back(Rows::value_type());
istringstream ss(row);
for (string field; getline(ss, field, field_delim); ) {
r... |
1,076,190 | 1,076,218 | 64 bit floating point porting issues | I'm porting my application from 32 bit to 64 bit. Currently, the code compiles under both architectures, but the results are different. For various reasons, I'm using floats instead of doubles. I assume that there is some implicit upconverting from float to double happening on one machine and not the other. Is ther... | There is no inherent need for floats and doubles to behave differently between 32-bit and 64-bit code but frequently they do. The answer to your question is going to be platform and compiler specific so you need to say what platform you are porting from and what platform you are porting to.
On intel x86 platforms 32-bi... |
1,076,316 | 1,076,394 | Excel document parser/importer? | Can anyone recommend a decent Excel (Binary XLS) document importer written in C?
I am looking to write a Ruby wrapper around one.
I haven't been able to find any via Google.
| Have you considered the source code of Gnumeric?
|
1,076,955 | 1,077,083 | C++ DLL Called From C# on Windows CE for ARM Always Returns 0 | I am currently developing an application for Windows CE on the TI OMAP processor, which is an ARM processor. I am trying to simply call a function in a C++ DLL file from C# and I always get a value of 0 back, no matter which data type I use. Is this most likely some kind of calling convention mismatch? I am compilin... | It worked when I changed:
extern "C" __declspec (dllexport) unsigned char test_return() {
return 95;
}
to
extern "C" __declspec (dllexport) unsigned char __cdecl test_return() {
return 95;
}
In the DLL code. Why it doesn't assume this when compiled for WinCE is beyond me.
|
1,077,216 | 1,077,229 | How do you Make A Repeat-Until Loop in C++? | How do you Make A Repeat-Until Loop in C++? As opposed to a standard While or For loop. I need to check the condition at the end of each iteration, rather than at the beginning.
| do
{
// whatever
} while ( !condition );
|
1,077,258 | 1,077,271 | Windows SearchPath function | I am using the following to search for a file defined as a macro DB_CONFIG_FILE_PATH_1.
wchar_t filename[100];
SearchPath( L".\\", DB_CONFIG_FILE_PATH_1, NULL, 100, filename, NULL);
If the file is in C:\ directory, it is found. But, if the file is in one of its sub-directories the function doesn't find it.
Can some ex... | For searching subdirectories in native code on Win32, you need to do it yourself, using FindFirstFile and then recursing into subdirectories.
The return value of FindFirstFile isn't a file handle - the file information is contained in the WIN32_FIND_DATA structure returned. The handle is used in calls to FindNextFile ... |
1,077,298 | 1,077,306 | How do you Specify a Method to be a Destructor Rather than a Constructor in C++? | How do you specify a method to be a destructor rather than a constructor in C++? This confuses me very much. I can't tell the difference between the two.
| Here's an example:
MyClass::MyClass() // Constructor
MyClass::~MyClass() // Destructor
Note the "~" in front of the destructor.
|
1,077,336 | 1,077,364 | OpenSource Instant Messaging APIs | I want to create my own IM and I'm searching an open-source IM APIs. What do you think is the best open-source IM APIs. And what good front end to use?
Thanks.
| If you are looking into making a client, check out libpurple. This is what pidgin and many other IM clients use to access multiple IM networks.
http://developer.pidgin.im/wiki/WhatIsLibpurple
If you are just worried about one IM network, the easiest one to work with would be Jabber because it is an open sourced proto... |
1,077,869 | 1,080,705 | Internet Explorer 8 + Deflate | I have a very weird problem.. I really do hope someone has an answer because I wouldn't know where else to ask.
I am writing a cgi application in C++ which is executed by Apache and outputs HTML code. I am compressing the HTML output myself - from within my C++ application - since my web host doesn't support mod_deflat... | The gzip and deflate methods aren't the same... they are very close, but there are some subtle differences with the header, so, if you change your content-encoding, you should also change your parameters to the encoding method (specifically, the window size)!
See: http://apcmag.com/improve_your_site_with_http_compressi... |
1,078,002 | 1,078,086 | how to write a virtual com port to TCP driver? | Hi I am trying to write a windows virtual com port driver which will divert the data to a IP address. any pointers, best practice will be of help?
| I know of a Open source project called com0com which is virtual com port redirector. there is a subproject called com2tcp in that which you can look atcom0com. otherwise for windows I am not sure you have any open source available
Between there are commercially available software such as the one from Eltima and tactica... |
1,078,218 | 1,078,254 | while (cin >> x) and end-of-file issues | I'm a little confused as to what's going on, i'm playing with some programs from "Accelerated C++", and have hit a problem with one of the early programs (page 35, if you happen to have a copy nearby).
It uses this snippet:
while (cin >> x) {
++count;
sum += x;
}
("count" is an integer, "x" is a double)
It works... | From one point of view, once you've hit the end of an input stream then by definition there's nothing left in the stream so trying to read again from it doesn't make sense.
However, in the case of 'end-of-stream' actually being caused be a special character like Ctrl-Z on windows, we know that there is the possibility ... |
1,078,312 | 1,078,325 | Return value of process | How can I get the return value of a process? Basically I'm **ShellExecute()**ing a .NET process from a DLL (in C++). The process does its task, but now I want to know whether it succeeded or failed. How to do that in WinAPI or MFC?
| Use ShellExecuteEx instead so you can get a handle to the process which was launched. You should then be able to use GetExitCodeProcess to obtain the exit code.
(I've left this answer here despite the similar one from MSalters, as I suspect you're using ShellExecute deliberately to get the shell behaviour instead of ex... |
1,078,768 | 1,079,040 | Is there a relation between integer and register sizes? | Recently, I was challenged in a recent interview with a string manipulation problem and asked to optimize for performance. I had to use an iterator to move back and forth between TCHAR characters (with UNICODE support - 2bytes each).
Not really thinking of the array length, I made a curial mistake with not using size_... | The C++ standard doesn't specify the size of an int. (It says that sizeof(char) == 1, and sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long).
So there doesn't have to be a relation to register size. A fully conforming C++ implementation could give you 256 byte integers on your PC with 32-bit registers. But it... |
1,078,775 | 1,123,964 | Is time.h clock() broken on my hardware? | I try to measure the clock cyles needed to execute a piece of code on the TMS32064x+ DSP that comes with the OMAP ZOOM 3430 MDK. I look at the "Programmer's Guide" of the DSP chip and it says that the DSP supports the clock() function.
What I do is really simple, I just do
start = clock();
for (i=0;i<100;i++){
/* d... | From reading the questions so far, I'd say the Original Poster has substantially more knowledge of this matter than the contributors so far, and that the suspicion that the clock() is broken (or not supported, and returns an undefined result) on the DSP seems quite likely.
|
1,078,939 | 1,079,007 | I'd like to call the Windows C++ function WinHttpGetProxyForUrl from Python - can this be done? | Microsoft provides a method as part of WinHTTP which allows a user to determine which Proxy ought to be used for any given URL. It's called WinHttpGetProxyForUrl.
Unfortunately I'm programming in python so I cannot directly access this function - I can use Win32COM to call any Microsoft service with a COM interface.
So... | You can use ctypes to call function in WinHttp.dll, it is the DLL which contains 'WinHttpGetProxyForUrl. '
Though to call it you will need a HINTERNET session variable, so here I am showing you the first step, it shows how you can use ctypes to call into DLL,it produces a HINTERNET which you have to pass to WinHttpGetP... |
1,079,020 | 1,079,032 | Can you expand #define's into string literals? | Is there a way to get the C++ pre-processor to expand a #define'ed value into a string literal?
for example:
#define NEW_LINE '\n'
Printf("OutputNEW_LINE"); //or whatever
This looks to me like it should be possible as it's before compilation?
Or is there a better design pattern to achieve this kind of behaviour (wit... | This will do it:
#define NEW_LINE "\n" // Note double quotes
Printf("Output" NEW_LINE);
(Technically it's the compiler joining the strings rather than the preprocessor, but the end result is the same.)
|
1,079,238 | 1,079,682 | Is it possible to get the debugger to display the name of the function pointed to by a boost function object? | When debugging code using boost function and bind in Visual Studio, I would like to be able to have the debugger show information about the actual function pointed to by the boost functor. For instance the name of the function, the signature of the original function (before bind was used on it), or the state of the fun... | There is an initiative in boost to make debug visualizers. There are already debug visualizers for different types (variant, multi_index, shared_ptr and more).
Unfortunately boost::function is not there, but you can write a visualizer yourself as described there (and maybe submit it to boost ;). Alternatively you can m... |
1,079,288 | 1,079,331 | how am i able to declare an array with variable length determined at runtime in C++? | Please check this code out it compiles and runs absolutely fine..
The question is that when i started learning c++ (turbo c++) i never was able to declare an array of any type as ..
datatype var[variable_set_at_runtime];
and i took it for granted that this cant be possible in latest gcc compilers...but surprisingly th... |
and i took it for granted that this
cant be possible in latest gcc
compilers...but surprisingly this is
possible...
It is legal in C, but not C++. GCC might allow it depending on compiler flags, but if you compile your code as strict C++ (which you should), dynamic-length arrays are not allowed, and you have to... |
1,079,522 | 1,079,699 | Question about operation on files in Windows | I have two HANDLEs and they are created from the same file,
in such condition I want to write on offset from 1 to 100 using the first HANDLE,
and from 101 to 200 using the 2nd HANDLE, from 201 to 300 using the first HANDLE,
...,
How can I make this operation seems like a sequential write and no time is wasted
between... | You should be able to do asynchronous overlapped IO.
To get you started, look at the WriteFile win32 API call. It discusses how to use CreateFile with the FLAG_FILE_OVERLAPPED flag. You then call WriteFile and pass in an OVERLAPPED parameter, which contains the offset to start writing at and an event handle, which ge... |
1,079,587 | 1,079,604 | Qt +hiding window after startup | I'm trying to hide window after its startup.
I have own window-class which is inherited from QMainWindow.
I rewrote showEvent like this:
void showEvent (QShowEvent *evt)
{
if (firstShow)
{
hide();
firstShow = false;
}
else
{
QMainWindow::showEvent(evt);
}
}
But it doesn't work. firstS... | I don't quite follow. Surely you just don't call show() on your main window in the first place?
|
1,079,623 | 1,079,631 | What is the lifetime of class static variables in C++? | If I have a class called Test ::
class Test
{
static std::vector<int> staticVector;
};
when does staticVector get constructed and when does it get destructed ?
Is it with the instantiation of the first object of Test class, or just like regular static variables ?
Just to clarify, this question came to my mind afte... | Exactly like regular static (global) variables.
|
1,079,748 | 1,079,760 | How to print '\n' instead of a newline? | I am writing a program that uses prints a hex dump of its input. However, I'm running into problems when newlines, tabs, etc are passed in and destroying my output formatting.
How can I use printf (or cout I guess) to print '\n' instead of printing an actual newline? Do I just need to do some manual parsing for this?
E... | Print "\\n" – "\\" produces "\" and then "n" is recognized as an ordinary symbol. For more information see here.
|
1,079,808 | 1,079,900 | Problem in using C dynamic loading routines | I have an application consisting of different modules written in C++.
One of the modules is meant for handling distributed tasks on SunGrid Engine. It uses the DRMAA API for
submitting and monitoring grid jobs.If the client doesn't supports grid, local machine should be used
The shared object of the API libdrmaa.so is... | It is very unlikely to be a direct problem with the code loaded via dlsym() - in the sense that the dynamic loading makes it seg-fault.
What it may be doing is exposing a separate problem, probably by moving stuff around. This probably means a stray (uninitialized) pointer that points somewhere 'legitimate' in the sta... |
1,079,850 | 1,079,857 | Adding MPI support to a C++ program | I have a program that is been implemented in C++ which I now want to add MPI support. There is an MPI binding for C++, with namespace MPI and everything.
In my case I have a specific object that is suitable to be the parallelized process into the cluster.
My questions are:
Has anyone done something like this before? C... | I would really recommend picking up the Gropp MPI Book, it really helps for basic MPI!
|
1,080,313 | 1,080,562 | MFC maximize window feature | I have tried to make the fullscreen feature of a SDI application with splitter windows by following the forum link. However, my status bar, system menu as well as the title bar of the application have disappeared. Do you have any suggestions on any easy ways of getting these back (or if I have to use different method o... | I got rid of any manipulations on the cs structure in the PreCreateWindow handler and used a ShowWindow(SW_MAXIMIZE) function call in the OnCreate function implementation of my MainFrame function, and it works quite well.
|
1,080,401 | 1,080,421 | What is the Basic Structure of a Function in FORTRAN? | This is something that's I've wanted to know recently, mostly out of curiousity. I'm in the mood to learn some old coding styles, and FORTRAN seems like a good place to start.
I guess I should help you guys out by providing a good starting point.
So how would this C procedure be written in FORTRAN?
int foo ( int x , ... | Where do you learn FORTRAN from? Just take a look at the wikibooks!
Derived from the example, I'd say:
function func(x, y) result(r)
integer, intent(in) :: x, y
integer :: r
integer :: tempX
tempX = x
x = x / 2
y = y - tempX * 3
r = x * y
end function foo
|
1,080,458 | 1,080,487 | Pattern for objects initialization at startup | I'm building an application and as time goes on, I have more and more objects to initialize at startup. Moveover, some of the newer objects depend on others so I'm getting some kind of spaggetti initialization where objects are created then passed to other constructors. I'm suspecting that I'm getting it wrong.
For exa... | This looks like a textbook case for using dependency injection (DI). It will certainly help with your spaghetti code and can even assist with unit testing. If you want to make a gradual migration towards DI you might want to consider refactoring the objects with similar relationships and using a few sets of factory cla... |
1,080,482 | 1,080,616 | C++ and Qt - encoding from page-content | Here is link where i got a code for web-page content fetching. But i have a trouble: i got text in wrong encoding. Could i correct it? Thanks.
EDIT:
I'm trying to get data from page:
http://ru.wiktionary.org/wiki/example
And got: alt text http://img44.imageshack.us/img44/6141/kfastwikimainwindow.png
EDIT2:
I just save ... | I think you're getting it with the correct encoding, it's just not being displayed with the correct encoding. I did a quick test and that's pretty much what it looks like when I display it with the Visual Studio HTML Visualizer, but if I save the data to file and open it with a browser, it is encoded correctly.
|
1,080,635 | 1,080,718 | Other's library #define naming conflict | Hard to come up with a proper title for this problem. Anyway...
I'm currently working on a GUI for my games in SDL. I've finished the software drawing and was on my way to start on the OpenGL part of it when a weird error came up. I included the "SDL/SDL_opengl.h" header and compile. It throws "error C2039: 'DrawTextW'... | You have a couple of options, all of which suck.
Add #undef DrawText in your own code
Don't include windows.h. If another library includes it for you, don't include that directly. Instead, include it in a separate .cpp file, which can then expose your own wrapper functions in its header.
Rename your own DrawText.
Whe... |
1,080,652 | 1,080,706 | How to check the length of an input? (C++) | I have a program that allows the user to enter a level number, and then it plays that level:
char lvlinput[4];
std::cin.getline(lvlinput, 4)
char param_str[20] = "levelplayer.exe "
strcat_s(param_str, 20, lvlinput);
system(param_str);
And the level data is stored in folders \001, \002, \003, etc., etc. However, I have... | Here's how you could do this in C++:
std::string lvlinput;
std::getline(std::cin, lvlinput);
if (lvlinput.size() > 3) { // if the input is too long, there's nothing we can do
throw std::exception("input string too long");
}
while (lvlinput.size() < 3) { // if it is too short, we can fix it by prepending zeroes
lvli... |
1,080,662 | 1,080,698 | Is this a good way to use dlls? (C++?) | I have a system that runs like this:
main.exe runs sub.exe runs sub2.exe
and etc. and etc...
Well, would it be any faster of more efficient to change sub and sub2 to dlls?
And if it would, could someone point me in the right direction for making them dlls without changing a lot of the code?
| DLLs would definitely be faster than separate executables. But keeping them separate allows more flexibility and reuse (think Unix shell scripting).
This seems to be a good DLL tutorial for Win32.
As for not changing code much, I'm assuming you are just passing information to theses subs with command line arguments. In... |
1,080,757 | 1,118,240 | Why is msbuild and link.exe "hanging" during a build? | We have a few C++ solutions and we run some build scripts using batch files that call msbuild.exe for each of the configurations in the solutions.
This had been working fine on 3 developer machines and one build machine, but then one of the projects started to hang when linking. This only happens on the newest machine ... | Whole-program optimization (/GL and /LTCG) and /MP don't mix -- the linker hangs. I raised this on Connect.
The upshot is that it's a confirmed bug in VS2008; contact PSS if you want a hotfix; and the fix is included in VS2010.
If you can't wait that long, turn off /MP (slower compiles) or /LTCG (slower code).
|
1,080,770 | 1,080,791 | Including Objective C++ Type in C++ Class Definition | I've got a project that is primarily in C++, but I'm trying to link in a Objective-C++ library. I have a header that looks something like:
CPlus.h:
#import "OBJCObject.h"
class CPlus {
OBJCObject *someObj;
};
CPlus.mm:
CPlus::CPlus() {
someObj = [[OBJCObject alloc] init];
}
When I import the Objective-C++ heade... | Are you #importing CPlus.h from an Objective-C (.m) file? If so, it will not understand the C++ class since it is being compiled with C semantics, and is not Objective-C++ aware. The .m compiler will see class and not know what to do.
You can include Objective-C objects in C++ class definitions, and vice versa, as long... |
1,080,805 | 1,080,836 | C++ - how does Sleep() and cin work? | Just curious. How does actually the function Sleep() work (declared in windows.h)? Maybe not just that implementation, but anyone. With that I mean - how is it implemented? How can it make the code "stop" for a specific time? Also curious about how cin >> and those actually work. What do they do exactly?
The only way I... | The OS uses a mechanism called a scheduler to keep all of the threads or processes it's managing behaving nicely together.
several times per second, the computer's hardware clock interrupts the CPU, which causes the OS's scheduler to become activated. The scheduler will then look at all the processes that are trying... |
1,080,876 | 1,080,947 | Adding a minimize button to a Qt dialog? | I have created a QDialog based app using Qt Creator and all is well other than the dialog has no minimize button. How can I add one? Is there a property in the designer that I can set?
| You can't add the minimize button yourself as it is handled by the window manager. You can tell the window manager how your dialog should be handled using Window Manager hints. This is done using the windowFlags property of your widget. There's also an example demonstrating this.
setWindowFlags(windowFlags() | Qt::Wind... |
1,080,953 | 1,080,995 | What is the simplest RTTI implementation for C++? | I'm trying to implement exception handling for an embedded OS and I'm stuck at how to detect the type of the thrown "exception" (to select the appropriate handler).
The saving and restoring context parts of the exception handling are already done, but I can't have specific handles since I can't detect the type of the t... | As you're working in an embedded environment, you presumably favour extremely minimal solutions and you can take advantage of non-standard or non-portable facts about your compiler.
If a class is polymorphic (has at least one virtual function of its own) in C++, it probably has a pointer to a vtable embedded somewhere ... |
1,081,040 | 1,081,047 | Linked List: Is this solution good? | I was looking for a way to avoid starting from the head of the list each time I want to find a node, so I thought of assigning indexes to nodes, keeping a pointer to a random (not exactly random; see below) node and then finding the pointer that's closest to the index I want to find. Allow me to explain with code:
// h... | If you need to access elements in the middle of the list, then you're better off using an array. A list is an abstract data structure (ADT) that can be implemented various ways. What you've essentially done is create a redundant representation that has the overhead of both methods.
The advantage of a linked list is th... |
1,081,250 | 1,081,262 | Why does a%b produce SIGFPE when b is zero? | Today I was tracking down a floating point exception in some code I had just written. It took a little while to find because it was actually caused by taking an integer mod zero. Obviously doing anything mod zero is not going to be defined but I thought it was strange that the error was so misleading. What is it within... | The operation triggers SIGFPE:
SIG is a common prefix for signal
names; FPE is an acronym for
floating-point exception. Although
SIGFPE does not necessarily involve
floating-point arithmetic, there is no
way to change its name without
breaking backward compatibility.
GDB is a bit clearer about this and ca... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.