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
806,300
806,461
Optimization settings in VS
I am working on an application/GUI created with Win32/ATL . So there is UI field( text field) which works fine as designed in debug build. With release build it gets malformed and it looks like the width of text field is infinite. It works fine in debug build but creating issues in release build. So my question how sam...
VC++ fills its runtime-memory in debug mode with special values. It does not ensure any fixed or zero-initialization though. Read this SO thread for details. Uninitialized Memory Blocks. These values may not crash the application every time. I have run into similar situations some times. One common example is that acc...
806,429
806,448
What is a good tutorial for C++ policy-based class design?
I have just started reading Modern C++ Design Generic programming and Design Patterns Applied and I am wondering if I need to go through some very basic tutorial on policy-based class design before I dive in. Will chapter 1 provide all I need to follow it? I am already experienced with template usage (STL/boost/Poco) a...
In my experience its pretty much a self contained book, as long as you know your way around C++. This is kind of a silly question. Just dive in the book, if something's not clear, look it up. Why ask questions about chaper 1 when you can just read it and find out? Fear is the mind-killer.
806,543
806,560
C++ Macros: manipulating a parameter (specific example)
I need to replace GET("any_name") with String str_any_name = getFunction("any_name"); The hard part is how to trim off the quote marks. Possible? Any ideas?
How about: #define UNSAFE_GET(X) String str_##X = getFunction(#X); Or, to safe guard against nested macro issues: #define STRINGIFY2(x) #x #define STRINGIFY(x) STRINGIFY2(x) #define PASTE2(a, b) a##b #define PASTE(a, b) PASTE2(a, b) #define SAFE_GET(X) String PASTE(str_, X) = getFunction(STRINGIFY(X)); Usage: SAFE_...
806,614
852,403
How to trace a certain object in VC++ 6
i was wondering how to trace a certain object in VC++6. It can be done by tracing the unique object ID with "Trace Points", in more recent versions of visual studio. I still haven't figured out how to do this in VC++ 6. Maybe you guys can point me in the right direction. Thanks in advance! Best regards, zhengtonic
click on object, go to break point and select trace point :)
806,830
806,880
Capture CPU and Memory usage dynamically
I am running a shell script to execute a c++ application, which measures the performance of an api. i can capture the latency (time taken to return a value for a given set of parameters) of the api, but i also wish to capture the cpu and memory usage alongside at intervals of say 5-10 seconds. is there a way to do this...
I'd suggest to use 'time' command and also 'vmstat' command. The first will give CPU usage of executable execution and second - periodic (i.e. once per second) dump of CPU/memory/IO of the system. Example: time dd if=/dev/zero bs=1K of=/dev/null count=1024000 1024000+0 records in 1024000+0 records out 1048576000 bytes ...
806,846
806,869
Query on Static member variables of a class in C++
Sorry if this question seems trivial to many here. In a C++ code there is something as below: class Foo { public: static int bands; ... ... private: ... ... }//class definition ends int Foo::bands; //Note: here its not initialized to any value! Why is the above statement needed again when 'bands' is ...
C++ notes a distinction between declaring and defining. bands is declared within the class, but not defined. A non-static data member would be defined when you define an object of that type, but since a static member is not a part of any one specific object, it needs it's own definition.
806,976
807,018
How to resolve this bad_alloc problem?
I'm developing an application that needs to interact over FTP. For this communication I am currently using C++, Visual Studio and Poco on Windows. The following line results in a bad_alloc exception... ftp = new FTPClientSession("127.0.0.1", 21); So I went down and tried initializing a StreamSocket first, also fails.....
I'm no rocket scientist but it looks like you'll have to step into IPv4AddressImpl() with ia.s_addr populated with a pointer to the string "127.0.0.1". Just out of interest, do you get the error when you use your real IP address instead of the loopback. And, do you have an FTP server running on that machine? And, are y...
807,073
807,088
What does object* foo(bar) do?
For some class C: C* a = new C(); C* b(a); //what does it do? C* b = a; //is there a difference?
C* b(a) and C* b = a are equivalent. As with many languages, there's more than one way to do it...
807,105
807,788
How to upload a file in C/C++ using HTTP with libcurl?
I would like to upload a file (a picture, in my case) in C/C++ using HTTP with libcurl. It will be great to have a working sample in C/C++ with (optional) the php code for the server side.
Check out the tutorial at the libcurl site.
807,245
808,242
Good, simple configuration library for large c++ project?
We are developing a rather large project in C++, where many components require configuration parameters. We would like to use a central place to configure everything (like a registry), preferably with a nice and simple GUI (e.g. like Firefox's about:config) and a simple API. I am pretty sure this that many application...
boost::program_options provides unified (and cross platform) support for configuration from command line, environment variables and configuration files. It seems like it ought to scale to multiple bits of a large software system registering an interest in various parameters (e.g option groups). Not much help with the...
807,846
807,864
Are there any articles or advice on creating a C++ chat server with a C# client?
My current class is planning on creating a basic networked game, but we have decided to take on the task of making a C++ server with a C# client. I understand this is probably a difficult task, but I was wondering if there is any advice on making this happen. I am sorry I do not have any more information than this. ...
This works fine. C# and C++ both support TCP and UDP network connections, in many flavors. Either would work fine for the client or server. The main issues you'll need to watch for are deciding how to transmit your data, and making sure that any packets you pass through the wire are serialized/deserialized the same w...
807,939
807,949
What is the difference between "new" and "malloc" and "calloc" in C++?
What is the difference between "new" and "malloc" and "calloc" and others in family? (When) Do I need anything other than "new" ? Is one of them implemented using any other?
new and delete are C++ specific features. They didn't exist in C. malloc is the old school C way to do things. Most of the time, you won't need to use it in C++. malloc allocates uninitialized memory. The allocated memory has to be released with free. calloc is like malloc but initializes the allocated memory with a c...
807,979
807,990
Efficient Huffman tree search while remembering path taken
As a follow up question related to my question regarding efficient way of storing huffman tree's I was wondering what would be the fastest and most efficient way of searching a binary tree (based on the Huffman coding output) and storing the path taken to a particular node. This is what I currently have: Add root node...
Create a dictionary of value -> bit-string, that would give you the fastest lookup. If the values are a known size, you can probably get by with just an array of bit-strings and look up the values by their index.
808,148
808,160
When to use Malloc instead of New
Duplicate of: In what cases do I use malloc vs new? Just re-reading this question: What is the difference between "new" and "malloc" and "calloc" in C++? I checked the answers but nobody answered the question: When would I use malloc instead of new? There are a couple of reasons (I can think of two). Let the best flo...
A couple that spring to mind: When you need code to be portable between C++ and C. When you are allocating memory in a library that may be called from C, and the C code has to free the allocation.
808,215
808,248
Is there a data structure that doesn't allow duplicates and also maintains order of entry?
Duplicate: Choosing a STL container with uniqueness and which keeps insertion ordering I'm looking for a data structure that acts like a set in that it doesn't allow duplicates to be inserted, but also knows the order in which the items were inserted. It would basically be a combination of a set and list/vector. I woul...
Take a look at Boost.MultiIndex. You may have to write a wrapper over this.
808,403
808,465
member template specialization and its scope
It appears to me that C++ does not allow member template specialization in any scope other than namespace and global scope (MS VSC++ Error C3412). But to me it makes sense to specialize a base class's primary member template in the derived class because that is what derived classes do - specialize things in the base cl...
I get what you're trying to do, but you are not doing it right. Try this : struct Base{}; struct Derived{}; // Original definition of Kind // Will yield an error if Kind is not used properly template<typename WhatToDo, typename T> struct Kind { }; // definition of Kind for Base selector template<typename T> struct Ki...
808,464
808,525
C++: new call that behaves like calloc?
Is there a call I can make to new to have it zero out memory like calloc?
Contrary what some are saying in their answers, it is possible. char * c = new char[N](); Will zero initialize all the characters (in reality, it's called value-initialization. But value-initialization is going to be zero-initialization for all its members of an array of scalar type). If that's what you are after. Wo...
809,227
809,341
Is it safe to use -1 to set all bits to true?
I've seen this pattern used a lot in C & C++. unsigned int flags = -1; // all bits are true Is this a good portable way to accomplish this? Or is using 0xffffffff or ~0 better?
I recommend you to do it exactly as you have shown, since it is the most straight forward one. Initialize to -1 which will work always, independent of the actual sign representation, while ~ will sometimes have surprising behavior because you will have to have the right operand type. Only then you will get the most hig...
809,289
809,315
C++ Concurrent GET requests
I am writing a C++ application and would like to request several data files through a HTTP GET request simultaneously, where should I look to get started (needs to be cross-platform). Run Application Create a list of URLs { "http://host/file1.txt", "http://host/file2.txt", "http://host/file3.txt"} Request all the UR...
I would recommend libcurl. I'm not super-familiar with it, but it does have a multi-interface for performing multiple simultaneous HTTP operations. Depending on what solution you go with, it's possible to do asynchronous I/O without using multithreading. The key is to use the select(2) system call. select() takes a ...
809,324
809,443
linker error: undefined reference c++
I've tried looking at similar problems, but could not easily find one that helped my problem. I've created a project in C++ and am working on UNIX to compile, link, and run it. My specific problem is an undefined reference to a method I declare in a separate file. In the file SharedCache.cpp, I have the following metho...
I've not used KDevelop, however, on the command line you would just add distributions.o as an input file to the linking process. No need for dashes or leaving off the .o extension. Alternatively, can you just add distributions.cpp to your KDevelop project? That way it should get compiled and linked automatically (this ...
809,334
809,342
Making a Point class in c++
Right now I am using std::pair to represent a 2d point in c++. However, I am getting annoyed with having to write typedef std::pair<double, double> Point; Point difference = Point(p2.first - p1.first, p2.second - p1.second); instead of being able to overload operator+ and operator-. So, my qu...
You could roll your own Point class, but use std::pair internally to store the data. This prevents the inheritance from STL issue, but still uses std::pair's functionality.
809,562
813,137
isAbstract template and visual studio
The following template will decide if T is abstract with g++. /** isAbstract<T>::result is 1 if T is abstract, 0 if otherwise. */ template<typename T> class isAbstract { class No { }; class Yes { No no[3]; }; template<class U> static No test( U (*)[1] ); // not defined template<class U> static Yes tes...
This works for me in VC9: template<typename T> class isAbstract { class No { }; class Yes { No no[3]; }; template<class U> static No test( U (*)[1] ); // not defined template<class U> static Yes test( ... ); // not defined public: enum { result = sizeof( test<T>( 0 ) ) == sizeof(Yes) }; }; Not...
809,807
809,817
How can I inhibit warning 4200 in Visual Studio 2005?
I can inhibit many warnings in Visual Studio 2005 SP1 in the C/C++ Advanced property page, which causes the IDE to use the /wd switch on the command line which invokes the compiler. However, when I try to inhibit warning 4200 (nonstandard extension used : zero-sized array in struct/union), it still appears when I compi...
You mean like with pragma? #pragma warning( disable : 2400 )
809,827
809,846
What is this programming technique? (Boost Library)
I'am trying to understand the example from program_options of the boost library (http://www.boost.org/doc/libs/1_38_0/doc/html/program_options/tutorial.html#id3761458) Especially this part: desc.add_options() ("help", "produce help message") ("compression", po::value<int>(), "set compression level") ; what exa...
The "add_options()" function actually returns a functor, that is, an object that overrides the () operator. This means that the following function call desc.add_options() ("help", "produce help message"); actually expands to desc.add_options().operator()("help", "produce help message"); The "operator()" also returns...
809,948
810,109
DLL References in Visual C++
I have had C++ experience but not MSVC. What I am trying to do is incorporate a .dll from an open source project into my project. The code is available and I have built it. I have the .dll as well as the .lib which as I understand it is required for C++ projects. Now unfortunately there is no simple "Add Reference", dr...
You need to do a couple of things to use the library: Make sure that you have both the *.lib and the *.dll from the library you want to use. If you don't have the *.lib, skip #2 Put a reference to the *.lib in the project. Right click the project name in the Solution Explorer and then select Configuration Properties-...
810,082
810,237
How does const after a function optimize the program?
I've seen some methods like this: void SomeClass::someMethod() const; What does this const declaration do, and how can it help optimize a program? Edit I see that the first part of this question has been asked before... BUT, it still doesn't answer the second part: how would this optimize the program?
If the compiler knows that the fields of a class instance are not modified across a const member function call, it doesn't have to reload any fields that it may have kept in registers before the const function call. This is sort of referred to the in C++ FAQ in the discussion on const_cast.
810,137
810,156
C++ - Passing Arrays To Methods
Here is a function similar to the one I've defined: void Function( BYTE *data ); What I would like to do is something like this: Function( new BYTE { 0x00, 0x00 } );
You cannot use the array initialiser syntax with dynamically allocated arrays using new. You could do something like this: BYTE *ary=new BYTE[2]; ary[0] = 0; ary[1] = 0; Function(ary); delete [] ary; But why are you using dynamically allocated memory here? Is the array held onto outside of the scope of the current fun...
810,177
810,551
Portable shared objects?
Is it possible to use shared object files in a portable way like DLLs in Windows?? I'm wondering if there is a way I could provide a compiled library, ready to use, for Linux. As the same way you can compile a DLL in Windows and it can be used on any other Windows (ok, not ANY other, but on most of them it can). Is tha...
I highly highly recommend using the LSB app / library checker. Its going to tell you quickly if you: Are using extensions that aren't available on some distros Introduce bash-isms in your install scripts Use syscalls that aren't available in all recent kernels Depend on non-standard libraries (it will tell you what di...
810,651
814,311
Help installing C++ for Netbeans
I am trying to install c++ for netbeans.. I tried installing the cygwin and mingw but i can't compile because the make file that comes with Mingw is incompatible ..
Try these Instructions from the Netbeans Website
810,657
1,413,048
Fastest code C/C++ to select the median in a set of 27 floating point values
This is the well know select algorithm. see http://en.wikipedia.org/wiki/Selection_algorithm. I need it to find the median value of a set of 3x3x3 voxel values. Since the volume is made of a billion voxels and the algorithm is recursive, it better be a little bit fast. In general it can be expected that values are rel...
Since it sounds like you're performing a median filter on a large array of volume data, you might want to take a look at the Fast Median and Bilateral Filtering paper from SIGGRAPH 2006. That paper deals with 2D image processing, but you might be able to adapt the algorithm for 3D volumes. If nothing else, it might g...
810,677
810,713
What utf format should boost wdirectory_iterator return?
If a file contains a £ (pound) sign then directory_iterator correctly returns the utf8 character sequence \xC2\xA3 wdirectory_iterator uses wide chars, but still returns the utf8 sequence. Is this the correct behaviour for wdirectory_iterator, or am I using it incorrectly? AddFile(testpath, "pound£sign"); wdirectory_i...
The encoding for wide chars (wchar_t objects) is implementation dependent. For the second statement (i.e. L"pound£sign") to work, you will probably need to change the underlying locale. The default is "C" which does not know about the pound character. The hex value succeeds since this does not require mapping the glyph...
810,839
810,850
Throwing exceptions from constructors
I'm having a debate with a co-worker about throwing exceptions from constructors, and thought I would like some feedback. Is it OK to throw exceptions from constructors, from a design point of view? Lets say I'm wrapping a POSIX mutex in a class, it would look something like this: class Mutex { public: Mutex() { ...
Yes, throwing an exception from the failed constructor is the standard way of doing this. Read this FAQ about Handling a constructor that fails for more information. Having a init() method will also work, but everybody who creates the object of mutex has to remember that init() has to be called. I feel it goes against ...
810,872
810,895
Best library for audio file meta data?
I am looking for a library to read meta data from compressed and uncompressed audio files (i.e. mp3, ogg, etc.). In the past I have used libvorbis and id3lib, but I'm wondering if there are better libraries around? Ideally I would like a library that provides a common API to reading meta data from all the various forma...
TagLib seems like a good candidate.
810,894
810,911
Reading cookies from default browser in C++
I want to create a c++ application that works together with a website. In order to keep the application synchronized with the website I want to be able to read some cookies from the user's default browser. Is there any way to do this?
Not in the general sense - there's no real defined format for cookie storage, so each browser is free to keep the cookie database wherever, and in whatever style, it prefers. You could implement cookie reading functions for the mainstream browsers (IE, Firefox), but that would leave some people out. It would also be no...
811,438
811,789
Which Logging tools do you use for Windows?
I'm looking at adding logging to an application, and I'm considering using Kiwi syslogd and a freeware library (clSyslog) to send logging messages to the daemon. I briefly looked at log4c, and found compiling it with VC++ would take me more time than I had. What tools do you use and recommend for logging messages?
In C++ I use a lot of log4cxx.. Don't see why it's a problem to compile, works like champ. It brings lots of benefits. To name just a few - you can re-direct your log statements into syslog or windows event log without ever touching your code base - just change configuration.
811,641
811,659
Windows Threading Wait Method
I'm creating a thread class to encapsulate the windows thread methods. I'm trying to create a method that makes the application wait for the thread to complete before it exits the application. If I use a while loop and boolean flag, it works but obviously it spikes my CPU use and it's just not ideal. What ways would yo...
After you use CreateThread to get a thread handle, pass it into the Win32 API WaitForSingleObject: WaitForSingleObject(threadhandle, INFINITE); If you do not use CreateThread (because you use another threading package), or perhaps your thread is always alive... Then you can still use WaitForSingleObject. Just create ...
811,720
811,890
C++ How to compile dll in a .exe
I am creating a c++ program, but I want to be able to offer just a .exe file to the user. However, I am using libraries (curl among others) which have some dll's. Is it possible to compile these dll's into the .exe file? I use Code::Blocks and mingw.
In order to achieve that you will need static linking. This requires that all your libraries (and the libraries they depend upon recursively) need to be available as static libraries. Be aware that the size of your executable will be large, as it will carry all the code from those static libraries. This is why shared l...
811,724
811,807
Why is the Visual C++ compiler calling the wrong overload here?
Why is the Visual C++ compiler calling the wrong overload here? I am have a subclass of ostream that I use to define a buffer for formatting. Sometimes I want to create a temporary and immediately insert a string into it with the usual << operator like this: M2Stream() << "the string"; Unfortunately, the program calls...
The compiler is doing the right thing: Stream() << "hello"; should use the operator<< defined as a member function. Because the temporary stream object cannot be bound to a non-const reference but only to a const reference, the non-member operator that handles char const* won't be selected. And it's designed that way, ...
811,951
811,980
/MT and /MD builds crashing, but only when debugger isn't attached: how to debug?
I have a small single-threaded C++ application, compiled and linked using Visual Studio 2005, that uses boost (crc, program_options, and tokenizer), a smattering of STL, and assorted other system headers. (It's primary purpose is to read in a .csv and generate a custom binary .dat and a paired .h declaring structures t...
One little know difference between running with debugger attached or not is the OS Debug Heap (see also Why does my code run slowly when I have debugger attached?). You can turn the debug heap off by using environment variable _NO_DEBUG_HEAP . You can specify this either in your computer properties, or in the Project S...
811,974
812,336
Search Outlook Contact using COM?
I want to add support for searching for local Outlook contacts to my ATL/WTL app. Does anyone know of the Outlook COM interface (Office 2003 or greater) allows you to search for contacts? I already have LDAP lookup support but users want to be able to search their private contacts as well. Any information would be we...
To get access to the contacts you first have to get a Namespace object using the Application's GetNamespace function, passing "MAPI" as the namespace name. Then you use Namespace's GetDefaultFolder function, which gives you a MAPIFolder interface which contains an Items property. Next you call the Find function on th...
812,409
812,423
How to design my classes to leverege factory and be extensible?
My c++ SOA app has a concept of "session" that is used exchange data between services. In example its used for checking legality of some service A operations before executing session B which commits or rollback changes. Whatever. I have 2 types of session modes: normal and what-if. Going further, I have different sessi...
Try to implement your WhatIf with decorators. Or extract some 'what if' specific parts to kind of strategy. Another option is using of the State pattern. 'WhatIf' state and 'Real' state.
812,717
815,197
Is there any reason to use C instead of C++ for embedded development?
Question I have two compilers on my hardware C++ and C89 I'm thinking about using C++ with classes but without polymorphism (to avoid vtables). The main reasons I’d like to use C++ are: I prefer to use “inline” functions instead of macro definitions. I’d like to use namespaces as I prefixes clutter the code. I see C++...
Two reasons for using C over C++: For a lot of embedded processors, either there is no C++ compiler, or you have to pay extra for it. My experience is that a signficant proportion of embedded software engineers have little or no experience of C++ -- either because of (1), or because it tends not to be taught on electr...
813,898
814,034
Handling TCHARs in header files for libraries with different character sets
I have a project that uses two third party libraries, both of which make use of TCHARs in their header files. Unfortunately one library is complied as multi-byte (call it library a), and the other is compiled as Unicode (call it library b). Now the way I understand it is that TCHAR is replaced by the precompiler with e...
Assuming you're not using too many class/function in either one of these libraries, I would wrap one of the library completely. Let's say if you decided to use mbc in your app and wrap library b (unicode), your wrapper header file can use wchar_t instead of TCHAR so #define will not affect your interface. Inside your w...
814,326
815,302
hardware buffering using SDL, question about how it works
I'm deciding to do my first game, its going to be simple but I want to use c++ and I chose SDL for my learning. So my question is about how the "buffers" are handled when writing code. I'll post my related code at the bottom. Ok, so basically the way I understand it is that SDL takes care of which buffer is actually be...
it highly depends on the your system (ie. X11, Linux frame buffer, Windows), and the backend SDL uses to interact with it. Also which flags you passs to SDL_SetVideoMode. There are basically software surfaces which sit in a region of memory in you program and hardware surfaces which are placed in graphical card's memor...
815,002
815,096
In Qt how do I get a button press to set a spinbox to a certain value?
I'm trying to get to grips with Qt's signal and slots mechanism. I have an app with a QPushButton and a QSpinBox. When I click the button I want the spinbox to change to 20. What signal and slot do I need to set up? The code below shows the app, the connect function is the one I am having trouble with. As I understand ...
You can either do: class AuxSignals : public QObject { Q_OBJECT ... signals: void valueChanged(int); public slots: void buttonClicked() { emit valueChanged(20); } }; ... // On main.cpp AuxSignals *auxSignals = new AuxSignals; QObject::connect(button, SIGNAL(clicked()), auxSignal, SLOT...
815,380
815,494
Wait until QWidget closes
I'm working on a project in C++ and QT, and I want to open a new QWidget window, have the user interact with it, etc, then have execution return to the method that opened the window. Example (MyClass inherits QWidiget): void doStuff(){ MyClass newWindow = new Myclass(); /* I don't want the code down...
Have MyClass inherit QDialog. Then open it as a modal dialog with exec(). void MainWindow::createMyDialog() { MyClass dialog(this); dialog.exec(); } Check out http://qt-project.org/doc/qt-4.8/qdialog.html
815,423
816,496
C/C++ Machine Learning Libraries for Clustering
What are some C/c++ Machine learning libraries that supports clustering of multi dimensional data? (for example K-Means) So far I have come across SGI MLC++ http://www.sgi.com/tech/mlc/ OpenCV MLL I am tempted to roll-my-own, but I am sure pre-existing ones are far better performance optimized with more eyes on code....
The Open Source C Clustering Library from the Human Genome team at the University of Tokyo looks promising. It has K-means as well as other flat hierarchical clustering algorithms. Scroll down in their page for the bare library without the GUI. The Wikipedia-Clustering project seems nice and a bit lighter. Here's a spe...
815,429
815,433
is it possible to use regex in c++?
Duplicate of: There is a function to use pattern matching (using regular expressions) in C++? I'm not sure where one would use it... are there any parser-type functions that take some regex as an argument or something? I just found out that my editor will highlight a line after / as "regex" for C/C++ syntax which I tho...
In the vanilla C++ language there is no support for regular expressions. However there are several libraries available that support Regex's. Boost is a popular one. Check out Boost's Regex implementation. http://www.onlamp.com/pub/a/onlamp/2006/04/06/boostregex.html http://www.boost.org/doc/libs/1_39_0/libs/regex/do...
815,581
816,073
Qt: creating an "svg image button"
I'm new to Qt so please excuse my ignorance. I am attempting to create a an 'svg image button' with QSizePolicy::Preferred for both horizontal and vertical. That part works. When the window is resized, the button grows and shrinks exactly how I want... But the image within the button stays the same size. I would like t...
This is how I eventually solved it: SVGPushButton::SVGPushButton(QString svgPath, QString name) : QPushButton() { setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); QSvgWidget *icon = new QSvgWidget(svgPath,this); setLayout( new QHBoxLayout(this) ); layout()->addWidget( icon ); }
815,956
3,593,296
Anyone have some TAP or SNPP examples?
Does anyone know of a good resource with some examples of using the Telocator Alphanumeric Protocol (TAP) and/or the Simple Network Paging Protocol (SNPP) in either C++ or C#? Thanks!
TAP Not C++ but: Perl Net::SNPP module
815,993
816,048
Visual Studio - New Filter instead of New Folder when using Create Project From Existing Source Wizard
I used the Create Project From Existing Code Wizard for Visual Studio 2008, but apparently projects created this way do not allow you to create virtual solution folders, and instead only allow you to create actual system folders. I would like to have the standard project setup of Header Files, Resource Files, and Sourc...
At least for a C++ project created this way (not sure about other languages), the "Show All Files" button/option in the Solution Explorer is enabled which gives the behavior you're seeing. Disable that option by clicking the icon and you'll get the behavior you're looking for.
816,001
816,008
Removing non-integers from a string in C++
There was a passing comment in a book of mine about people inputting commas into integers and messing up your program, but it didn't elaborate. That got me thinking, so I tried writing a little algorithm to take an std::string and remove all non-integer characters. This code compiles but skips over output. Why isn't an...
newstring is of length 0, so newstring[x] where x=0 is actually illegal. You should append to the string using: newstring.append(1, fstring[i]) For the secondary question, look for atoi(), atof(), strtol(0, strtof() functions.
816,092
816,613
Typographic apostrophe + wide string literal broke my wofstream (C++)
I’ve just encountered some strange behaviour when dealing with the ominous typographic apostrophe ( ’ ) – not the typewriter apostrophe ( ' ). Used with wide string literal, the apostrophe breaks wofstream. This code works ofstream file("test.txt"); file << "A’B" ; file.close(); ==> A’B This code works wofstream file(...
You should "enable" locale before using wofstream: std::locale::global(std::locale()); // Enable locale support wofstream file("test.txt"); file << L"A’B"; So if you have system locale en_US.UTF-8 then the file test.txt will include utf8 encoded data (4 byes), if you have system locale en_US.ISO8859-1, then it would ...
816,143
830,580
image subdirectory in c++
Basically, I was hoping to sort of keep my files sorted instead of having them all in the same folder as my executable, but referencing files in sub folders relative to my executable has proven difficult. // DEFINES #define IMAGE_BACKGROUND "\\content\\images\\background.bmp" #define FONT_MAIN "\\content\\fonts\\sai.tt...
I actually solved it by using the following code, thank you all for the responses: // DEFINES #define IMAGE_BACKGROUND ".\\content\\images\\background.png" #define IMAGE_BLUEBLOCK ".\\content\\images\\blueblock.png" #define FONT_MAIN ".\\content\\fonts\\sai.ttf" Turns out the . gets the "working path directory".
816,232
816,483
Traverse from end to front ( C++ LL Q:1 )
int LinkedList::DoStuff() { Node *Current = next_; while ( Current != NULL ) { Current = Current->next_; length_++; } // At the last iteration we have reached the end/tail/last node return length_; } there are no more nodes beyond the last. How can i traverse to the tail-end to the...
Recursion can work, as can building an auxiliary data structure, such as an array with one entry for each element of the original list. If you want a solution for a single-threaded list without requiring O(n) extra storage, the best bet is to reverse the list in place as Michael suggests. I wrote an example for this,...
816,463
816,470
Why won't a derived class work in an array? (C++)
I've created a class, called vir, with a function move: class vir { public: vir(int a,int b,char s){x=a;y=b;sym=s;} void move(){} }; (It's derived from a class with variables int x, int y, and char sym) I have derived a class from this, called subvir: class subvir:public vir { public: subvir(int a,int b...
You need an array of pointers in this case, rather than an array of instances. Use vir*[] instead of vir[]
816,714
816,734
A good (and free) VCL GUI alternative
I've got a project with a rather messy VCL codebase built on Borland C++ Builder 6. I intend to rewrite most parts of it since it's hardly maintainable in it's current state. I'm looking for a good and free alternative to VCL. It is a Windows-only closed source commercial project. So main requirements are: Free for co...
Try Qt. Its LGPL so it can be used in closed source software. It provides widgets, networking functions, database access, web rendering via WebKit, animations and many more. Its documentation is one of the best of its kind.
817,263
817,266
Is it possible to create a vector of pointers?
Just wondering, because of a problem I am running into, is it possible to create a vector of pointers? And if so, how? Specifically concerning using iterators and .begin() with it, ie: How would I turn this vector into a vector of pointers: class c { void virtual func(); }; class sc:public c { void func()...
vector <c> cvect is not a vector of pointers. It is a vector of objects of type c. You want vector <c*> cvect. and the you probably want: cvect.push_back( new c ); And then, given an iterator, you want something like: (*it)->func(); Of course, it's quite probable you didn't want a vector of pointers in the first pla...
817,337
817,348
I notice ints and longs have the same size. Why?
Just noticed this on OSX and I found it curious as I expected long to be bigger than int. Is there any good reason for making them the same size?
This is a result of the loose nature of size definitions in the C and C++ language specifications. I believe C has specific minimum sizes, but the only rule in C++ is this: 1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) Moreover, sizeof(int) and sizeof(long) are not the same size on all platforms. ...
817,429
817,449
Why is my vector code asserting? What is an assert anyway?
What exactly is an "assert", or more specifically, how do I get rid of an error. When I create a vector of pointers to a class with data member int x, and then do this: for(I=antiviral_data.begin();I<antiviral_data.end();I++) { if((*I)->x>maxx) { antiviral_data.erase(I); } } And run the program, I...
The most probable reason why you get the assertion is that you increment I after an erase. Try this instead: for(I=antiviral_data.begin();I!=antiviral_data.end();) { if((*I)->x>maxx) I=antiviral_data.erase(I); else ++I; } See also http://www.cppreference.com/wiki/stl/vector/erase , search for invalid iterators on ...
817,491
817,579
C++ Exp vs. Log: Which is faster?
I have a C++ application in which I need to compare two values and decide which is greater. The only complication is that one number is represented in log-space, the other is not. For example: double log_num_1 = log(1.23); double num_2 = 1.24; If I want to compare num_1 and num_2, I have to use either log() or exp(),...
AFAIK the algorithms, the complexity is the same, the difference should be only a (hopefully negligible) constant. Due to this, I'd use the exp(a) > b, simply because it doesn't break on invalid input.
817,604
817,683
Faster abs-max of float array
I need to draw peak meters for audio in realtime. Minimum 44100 samples per second times a minimum 40 streams. Each buffer is between 64 and 1024 samples. I need to grab the abs max from each buffer. (These are then fed through a kind of lowpass filter and drawn at about 20ms intervals.) for(int i = 0; i < numSamples; ...
fabs and comparison are both really fast for IEEE floats (like, single-integer-op fast in principle). If the compiler isn't inlining both operations, then either poke it until it does, or find the implementation for your architecture and inline it yourself. You can maybe get something out of the fact that positive IEEE...
817,627
817,649
Brand new to C (how to compile?)
I would like to know what I should use to compile in C. I am brand new to programing in general and would greatly appreciate a comprehensive explanation of this process. I am on Windows Vista. I heard about something called "djgpp" that is free and effective for windows.
For the answer to this question and many others you may have as you start out, try [this website][1] which has beginner tutorials. [Here's the page][2] on compilers and getting set up. An excerpt on what compilers you can use: Windows/DOS Code::Blocks and MINGW Borland DJGPP Dev-C++ and Digital Mars Windows Only Mi...
817,769
817,802
How to log stuff in console in Visual Studio C++
I'm working on a little C++-Game in Visual Studio 2008. I want to see the content of a vector after a couple of seconds or after I pressed some buttons. Breakpoints are useless in this case, because they stop me at every call of the gameloop (~60 times per second). How do I debug in this case? Thanks!
Use function OutputDebugString from Windows API. You can call it anytime you want e.g. every 100th loop in your code. Function info is here Please read all comments on this page - some people claim that in your IDE (VS2008) output of this function is shown in "Immediate Window" not the "Output".
817,975
817,989
How can I get rid of the warning with rand()? (C++)
Whenever I use the rand function in C++: #include<iostream> #include<time.h> #include<stdlib.h> using namespace std; int main(){ srand(time(0)); int n=(rand()%6)+1; cout<<"The dice roll is "<<n<<"."<<endl; } I get a warning about conversion from time_t to int at line 5: srand(time(0)); Is there any way to get rid of ...
Actually, you should be using an an unsigned int with srand(): srand((unsigned) time(0));
818,141
818,305
SQLite C++ Access Columns by Name
Is there a way to access SQLite results by column name (like a C++ Map) instead of index number in C/C++? For example, Python's SQLite access allows dictionary access Results = Query("SELECT * FROM table"); print Results['colname'] print Results['anothercol'] Any similar methods available in C++ for the SQLite's int...
I'd go with Daniel in recommending SQLAPI++ at www.sqlapi.com -- at http://www.sqlapi.com/HowTo/fetch.html you can find a simple example of fetching fields by name. The example is a bit verbose so here's a code-only gist: void showemps(SAConnection* pconn, int minage) { SACommand cmd(pconn, "select name, age from em...
818,155
818,173
SQLite Alternatives for C++
I am developing a application that needs to store data with many writes and reads as requiring fast searching of data (the need for indexes of some sort), and also be able to serialize and save the data. Currently I am thinking about using SQLite, which gets the job done, but I am open for alternatives. The SQLite's s...
Stay with SQLite but find a good C++ library for this. This StackOverflow question should help you ...
818,208
818,215
Trouble with seekp() to replace portion of file in binary mode
I'm having some trouble with replacing a portion of a file in binary mode. For some reason my seekp() line is not placing the file pointer at the desired position. Right now its appending the new contents to the end of the file instead of replacing the desired portion. long int pos; bool found = false; fstream file(fil...
I don't see how your while() loop can work. In general, you should not test for eof() but instead test if a read operation worked. The following code writes a record to a file (which must exist) and then overwrites it: #include <iostream> #include <fstream> using namespace std; struct P { int n; }; int main() { ...
818,259
818,268
C++ how to call a parent class method from contained class?
I am trying to make a call to a Parent class method from a contained object, but have no luck with the following code. What is the standard way to do it? I have searched around and this seems to work for inherited objects, but not for contained objects. Is it right to call it a Parent class even? Or is it called an Own...
A contained object has no special access to the class that contains it, and in general does not know that it is contained. You need to pass a reference or a pointer to the containing class somehow - for example: class Child{ public: void doOtherThing( Parent & p ); }; void Child::doOtherThing( Parent & p ){ p.doS...
818,534
819,007
How do I set the color of a single pixel in a Direct3D texture?
I'm attempting to draw a 2D image to the screen in Direct3D, which I'm assuming must be done by mapping a texture to a rectangular billboard polygon projected to fill the screen. (I'm not interested or cannot use Direct2D.) All the texture information I've found in the SDK describes loading a bitmap from a file and a...
First, your direct question: You can, technically, set pixels in a texture. That would require use of LockRect and UnlockRect API. In D3D context, 'locking' usually refers to transferring a resource from GPU memory to system memory (thereby disabling its participation in rendering operations). Once locked, you can mo...
818,647
818,664
Where can I find good C++ source code?
I am learning C++ as a first language. I feel like I am about to hit a ceiling on my learning (I am not learning through a class) if I don't start looking at actual code soon. Here are my two main questions: Where can I find source code What is a good litmus test on code's quality (I've obviously never developed in a ...
I would recommend Boost. Using Boost will simplify your program design. Reading Boost source code can show you how to use C++ to solve some challenging problems in a concise way. This add on library is itself written in C++, in a peer-reviewed fashion, and has a high standard of quality.
818,665
819,528
How to check if socket is closed in Boost.Asio?
What is the easiest way to check if a socket was closed on the remote side of the connection? socket::is_open() returns true even if it is closed on the remote side (I'm using boost::asio::ip::tcp::socket). I could try to read from the stream and see if it succeeds, but I'd have to change the logic of my program to mak...
If the connection has been cleanly closed by the peer you should get an EOF while reading. Otherwise I generally ping in order to figure out if the connection is really alive.
818,762
819,002
Unflip wxImage loading
I have the code here working fine except that all the non-power of 2 images are flipped in the y direction. In the wxImageLoader file there is this loop which I believe is the culprit: for(int y=0; y<newHeight; y++) { for(int x=0; x<newWidth; x++) { if( x<(*imageWidth) && y<(*image...
The correct for loop is: for(int y=0; y<newHeight; y++) { for(int x=0; x<newWidth; x++) { if( x<(*imageWidth) && y<(*imageHeight) ){ imageData[(x+y*newWidth)*bytesPerPixel+0]= bitmapData[( x+y*(*imageWidth))*old_bytesPerPixel + 0]; imageD...
818,947
819,004
chaining c++ streams
I was thinking of "chaining" a couple of c++ iostreams toghether to filter input twice. I'm using gzstreams to read zlib compressed files and I was thinking of coding a stream that reads from a stream and performs encoding conversions. Perhaps by passing an opened stream as constructor parameter... How do you think thi...
I haven't used this but boost's filtering_stream may help. As an example I found a mailing list post with indent.hpp, which implements an output filter that indents outputs: boost::iostreams::filtering_ostream out; indent_filter::push(out,2); out.push(std::cout); And use it like so: out << "Hello Filter!\n" ...
818,981
820,596
In qt, how do I implement a widget that stays consistent with variables in the code
Here's a sample of a SpinBox that writes its changes to underlying variables. The main problem that I'm having is valueChanged is called when the widget is constructed. Is there a more elegant way to do this? I think it's weird that I connected a widget to itself, but valueChanged isn't virtual. class ValueWriterInt...
I see nothing particularly weird about connecting a widget to itself. Having a single method of detecting and responding to data updates actually sounds like a good thing because you have fewer points of failure to check when you are debugging. In your specific case, it is causing some undesired behavior, but in genera...
819,268
819,275
How to get the underlying stdio FILE* of a managed System.IO.FileStream?
I'm writing a .NET adaptor for a C/C++ library where a method "bar" takes a regular stdio FILE*. Is it possible to build an interface so that managed code user can pass a managed (File)Stream? That is without creating an intermediary buffer and code to pipe the data between. Also does the assumption that bar() reads on...
System.IO.FileStream.Handle It's not necessarily stdio handle. It's a Windows handle. I don't think FileStream is built upon stdio to have a stdio handle. As Marc pointed out and mentioned in the MSDN link, you might want to consider using SafeFileHandle property (if you are on .NET 2.0+) instead of Handle (which is no...
819,425
819,988
Why does C++ need language modifications to be "managed"?
Why can't a compiler be written that manages what needs to be managed in C++ code (i.e. to make it "CLR compatible")? Maybe with some compromise, like prohibiting void pointers in some situations etc. But all these extra keywords etc. What's the problem that has to be solved by these additions? I have my thoughts about...
I'd have to disagree with the answers so far. The main problem to understand is that a C++ compiler creates code which is suitable for a very dumb environment. Even a modern CPU does not know about virtual functions, hell, even functions are a stretch. A CPU really doesn't care that exception handling code to unwind th...
819,481
819,500
Better alternative for c++ old feature?
c++ has come a long way, it has lot of feature that lead to do same task in n number of ways. What feature do you think should be avoided and list better alternative for the same. Like use SmartPointers in places of pointers
Avoid malloc, use new. Avoid memcpy, use a copy constructor. Avoid #defines, use consts. Avoid (C-style) casts, use static_cast<C++>( style casts ). Avoid macros, use templates. Avoid post-increment if you can use pre-increment. Avoid new, use collections of value types, let the collection deal with memory management. ...
819,483
829,175
Is there a WinXP/WinXP Embedded API to change Locale (specifically, IME)?
I am looking for an API on WinXP to switch between installed IME's. The scenario is, to be able to plug in a langauge keyboard (say Spanish) and change the IME by clicking on a UI button (say button named Spanish) e.g. I plug in a Spanish keyboard and click on the UI button named Spanish. This should internally change ...
I was trying to change the locale/ IME (which falls under the locale). I found that there is an api named, 'SystemParametersInfo' which allows us to make settings on system level. In my case, I had to go to Control Panel > Regional Settings > and then switch between installed locales under Language tab. This could fina...
819,487
822,128
Efficiently convert between Hex, Binary, and Decimal in C/C++
I have 3 base representations for positive integer numbers: Decimal, in unsigned long variable (e.g. unsigned long int NumDec = 200). Hex, in string variable (e.g. string NumHex = "C8") Binary, in string variable (e.g. string NumBin = "11001000") I want to be able to convert between numbers in all 3 representations i...
As others have pointed out, I would start with sscanf(), printf() and/or strtoul(). They are fast enough for most applications, and they are less likely to have bugs. I will say, however, that these functions are more generic than you might expect, as they have to deal with non-ASCII character sets, with numbers repr...
819,525
819,898
How do I disable exp/lib generation when building an exe?
I realize this is probably caused by some _dllexport() somewhere, not in my code but in some third-party piece. (Qt, Boost, OpenSG, ...) Is there a simple linker option to disable this? I've searched but not found anywhere.
AFAIK, no, because the relevant #pragma's override the linker settings.
819,536
819,629
How to call Java functions from C++?
How can I call Java functions from a C++ application? I know about calling them from CMD (or similar techniques), but I would rather not use them.
As an example, check Creating a JVM from C. It shows a sample procedure to create a JVM and invoke a method. If the JVM already exists; e.g. your C program is invoked by the Java program (callback situation), you can cache the JNIEnv* pointer. As an advice, be careful caching pointers to the JVM from C/C++, there are ...
819,708
821,280
PID from socket number on Windows?
I need to count amount of bytes sent and received from the network by various applications. First I thought about using LSP, but there is a lot of applications that do not use LSP at all (SMB for example). This is why I have written a small sniffer. This application works on the IP level and collects data using recvfro...
Using GetTcpTable or AllocateAndGetTcpExTableFromStack is not a workaround. It's actually how other netstat-type applications work. As far as I know, there isn't any Win32 "GetPIDOfSocket" function. Your only option is to poll using the port table functions. But at least you can code it up yourself and don't have to sp...
819,710
819,735
DuplicateHandle(), use in first or second process?
The Windows API DuplicateHandle() http://msdn.microsoft.com/en-us/library/ms724251(VS.85).aspx Requires the Object handle to be duplicated and a handle to both the original process AND the other process that you want to use the duplicated handle in. I am assuming that if I have two UNRELATED processes, I could call Du...
Use a named pipe or mailslots for IPC, this should work reliably for your purpose. If you need to wait, use named wait handles. Otherwise, I'd choose to do DuplicateHandle in the second process in order to set the handle ownership correctly.
819,953
897,288
How to start writing a music visualizer in C++?
I'm interested in learning to use OpenGL and I had the idea of writing a music visualizer. Can anyone give me some pointers of what elements I'll need and how I should go about learning to do this?
If you use C++/CLI, here's an example that uses WPF four (fourier that is;) display. He references this site (archived) that has considerable information about what your asking, here's anoutline from the specific page; How do we split sound into frequencies? Our ears do it by mechanical means, mathematicians do it...
820,074
820,109
Which IDE does Google use for C++ and Java development
I am curious which IDE does Google use for C++ and Java development?
Mehrdad is very correct that it is highly unlikely that they standardize on one IDE for each language. However, there is probably a popular one or two for each language. A good way to tell is to look at the source code they release that would need an IDE plugin, and see what they support. I notice (regarding Java) Inte...
820,213
820,238
New to C++: should I use Visual Studio?
I'm about to start work on my first C++ project. I've done lots of C# and VB (VB6 and VB.NET), plus Java and a few other things over the past 10 years or so, just never had a requirement for C++ until now. I plan to use Visual Studio 2008, but I'm interested to find out from experienced C++ programmers whether Visual S...
First off, VS 2008 is quite powerful and probably one of the best IDEs for C++ programming (at least with a supporting plugin such as Visual Assist X). Beware, however, that C++ is a hard language to get right for the compilers and that the default warning level is quite lenient to boot. So it will tolerate bad/wrong c...
820,569
820,861
Is there a Perl script to implement C++ Class get/set member functions?
I was reading this morning the book The Pragmatic Programmer Chapter 3 on Basic Tools every programmer should have and they mentioned Code Generation Tools. They mentioned one Perl script for C++ programs which helped automate the process of implementing the get/set() member functions for private data members. Does any...
Although it doesn't directly answer your question, you may find that generated code is actually unnecessary for managing properties in C++. The following template code will allow you to declare and use properties conveniently: // Declare your class containing a few properties class my_class { public: property<int>...
820,664
820,744
'mpirun' is not recognized as an internal ort external commands,
I need to make a small openMP project. I took the example from the www.openmp.org. I can compile it with /openmp option within VC++ 2005. But, When I try to run the program, I am facing the "'mpirun' is not recognized as an internal ort external commands, operable program or batch file" error. When I search the net. I ...
You mention that you are using OpenMP - you shouldn't actually need to use mpirun or mpiexec, as you would with MPICH or OpenMPI programs. OpenMP works in a fairly different way than message-passing libraries: OpenMP uses multiple threads within the same process, but MPICH and OpenMPI use multiple processes. So if I un...
820,846
821,189
RegOpenKeyEx fails on HKEY_LOCAL_MACHINE
Hi I'm trying to read a registry value that gives me the path to firefox.exe. This is stored under HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox 3.0.10\bin (the version number can be found somewhere else) But I cant seem to get RegOpenKeyEx to return ERROR_SUCCESS for anything under HKEY_LOCAL_MACHINE so this t...
The following code failed on my machine with the error code 161, which means "bad path" (look it up in winerror.h): long n = RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE"), 0,KEY_QUERY_VALUE, &hk ); I then changed the call to RegOpenKeyEx to use "SOFTWARE" (note no leading slashes) and it worke...
820,859
820,890
Determining whether an object is in a std::set
I'm trying to determine whether an object is already contained within a std::set. According to msdn (and other sources) the set::find function is supposed to return end() if it doesn't find the element you asked for. However when I implement code like the following, set::find returns junk (0xbaadf00d) instead. set<Cell...
Your code as posted will always execute the code within the if, and 0xbaadf00d is the implementation's "one-past-the-end" marker.
821,667
821,709
C++ Problem initializing an object twice
I'm relatively new to C++ and am having a hard trouble understanding the instantiation of object and pointers to objects. Whats the difference between these two declaration in terms of memory and usage? : MyClass obj1; MyClass *obj2; And also the specific problem I am having is that I have a class which has an unsigne...
The difference: MyClass obj1; MyClass *obj2; Here obj1 is an instance of MyClass. While obj2 can potentially hold the address of an instance of MyClass. Also obj1 will automatically be initialized by the constructors, while obj2 is not initialized by default (and thus points to random memory). Once initialized obj2...
821,676
821,698
How do I decide whether to use ATL, MFC, Win32 or CLR for a new C++ project?
I'm just starting my first C++ project. I'm using Visual Studio 2008. It's a single-form Windows application that accesses a couple of databases and initiates a WebSphere MQ transaction. I basically understand the differences among ATL, MFC, Win32 (I'm a little hazy on that one actually) and CLR, but I'm at a loss as t...
It depends on your needs. Using the CLR will provide you with the most expressive set of libraries (the entire .NET framework), at the cost of restricting your executable to requiring the .NET framework to be installed at runtime, as well as limiting you to the Windows platform (however, all 4 listed technologies are w...
821,873
822,032
How to open an std::fstream (ofstream or ifstream) with a unicode filename?
You wouldn't imagine something as basic as opening a file using the C++ standard library for a Windows application was tricky ... but it appears to be. By Unicode here I mean UTF-8, but I can convert to UTF-16 or whatever, the point is getting an ofstream instance from a Unicode filename. Before I hack up my own soluti...
The C++ standard library is not Unicode-aware. char and wchar_t are not required to be Unicode encodings. On Windows, wchar_t is UTF-16, but there's no direct support for UTF-8 filenames in the standard library (the char datatype is not Unicode on Windows) With MSVC (and thus the Microsoft STL), a constructor for file...
822,059
824,873
SFINAE with invalid function-type or array-type parameters?
Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main() { char c[sizeof(f<void()>(0)) == 2]; } I expected it doing SFINAE and chosing the second overload, since substitution of T into T[1] yields void [1]() Which is an invalid type, of course. Adjustme...
A small note, although very rare, I have found some occasions where I believe that the Comeau compiler has it wrong - although, these occasions are so rare that its always worth double and triple checking your assumptions! I may have a reason for the behaviour of g++. I'm not sure its specified exactly when parameter ...
822,066
822,236
Native C++ or .NET for Business App?
Here's the deal: I'm in the process of planning a mid-sized business application that absolutely must support Win2k. AFAIK, official .NET support for Win2k was scrapped a while ago (IIRC, it stopped at version 2.0). Now, I already wrote (ages ago) libraries in C++ that allow me to accomplish the end result (i.e., finis...
The last .NET version that runs under Windows 2000 is .NET 2.0 SP2. It does include the features required by System.Core.dll (that is part of .NET 3.5). The answer is YES, you can use .NET 3.5 SP1 under Windows 2000 if you're not going to use .NET 3.0 libraries (WCF, WF, WPF, CardSpace). But you have LINQ, LINQ to XML,...
822,182
822,283
What is the most random function in C++?
I've used #include<stdlib> #include<time> using namespace std; srand((unsigned)time(0)); int n=(rand()>>8)%4; but what other random functions are there, or what other function could be used as random number generators? EDIT: I don't really have a particular reason for asking this question, I just wanted to know if C+...
The rand() and srand() functions are all the C++ Standard specifies. And if it comes to writing your own, be aware of what John von Neumann said: "Anyone who considers arithmetical methods of producing random digits is of course in a state of sin"
822,581
822,591
What C++ library should I use to implement a HTTP client?
I'm looking for a C++ library that implements or enables the implementation of a HTTP client. It should handle cookies as well. What would you propose?
Curl++: is an option, particularly if you want things in more of a C++ style. cpp-netlib: very good and simple to use, available on ubuntu sudo apt-get install libcppnetlib-dev example: using namespace boost::network; using namespace boost::network::http; client::request request_("http://127.0.0.1:8000/"); request_ ...
822,714
822,857
How to download a file with WinHTTP in C/C++?
I know how to download an html/txt page. For example : //Variables DWORD dwSize = 0; DWORD dwDownloaded = 0; LPSTR pszOutBuffer; vector <string> vFileContent; BOOL bResults = FALSE; HINTERNET hSession = NULL, hConnect = NULL, hRequest = NULL; // Use WinHttpOpen to obtain a session handle. hS...
Looks like this thread on MSDN is the same and has the solution http://social.msdn.microsoft.com/forums/en-US/vclanguage/thread/45ccd91c-6794-4f9b-8f4f-865c76cc146d
822,728
822,999
How to create/run a .exe from a program? (C++)
Is it possible (and if so, how) to write a program in C++ that takes parameters, then run that program from another C++ program. Ie: I can create a function that adds two numbers: int add(int a,int b){return a+b;} Is it possible to do the same thing, except instead of a function, a separate C++ .exe? EDIT: Since a lo...
On most OSes, you can pass arguments in system() by space-seperating them: system("someapp.exe 42 24"); This string, of course, can be built up by sprintf or std::ostringstream or what have you. Then you just need to process your arguments in the other program: int main(int argc, char **argv) { // important - make s...