1,247 Posted Topics
Re: See http://wiki.codeblocks.org/index.php?title=Creating_a_new_project In particular, http://wiki.codeblocks.org/index.php?title=Creating_a_new_project#Adding_a_blank_file http://wiki.codeblocks.org/index.php?title=Creating_a_new_project#Adding_a_pre-existing_file http://wiki.codeblocks.org/index.php?title=Creating_a_new_project#Removing_a_file | |
Re: > Are you talking about hashmaps ? Or map in C++ ? Don't think so. Just about sorting both strings and the determining their set intersection. char amit[] = "AMITABH BACHCHAN" ; char rajn[] = "RAJNIKANTH" ; std::sort( std::begin(amit), std::end(amit)-1 ) ; std::sort( std::begin(rajn), std::end(rajn)-1 ) ; std::set_intersection( std::begin(amit), std::end(amit)-1, … | |
Re: > while const int may not even be given storage because the compiler may just treat it as if it were a macro by inserting its value wherever it is used. Yes, an object of type const int need not be stored anywhere. But then, the same is also true … | |
Re: CBase b; void func_set(CBase *pb) // pb may point to an object which has the dynamic type of some derived class of CBase { b = *pb; // the object *pb may be sliced here } See http://stackoverflow.com/questions/274626/what-is-the-slicing-problem-in-c > You probolly can get away with changing line 24 to > … | |
Re: > If you know where Bjarne has explained this, then say so, because I can't see it. I suppose it must be there somewhere in his book. Its definitely there on his support site for the book. http://www.stroustrup.com/Programming/std_lib_facilities.h | |
Re: You should not be using a name like `_FOO` **anywhere** in your code. A name like `_fOO` can be used except in the global unnamed namespace. Just make sure that the character following the leading underscore is a lower case character. | |
Re: Use `std::uninitialized_copy()` instead of `std::copy()` http://en.cppreference.com/w/cpp/memory/uninitialized_copy | |
Re: The typical C++ approach is to simulate multimethods with multiple dispatch http://en.wikipedia.org/wiki/Multiple_dispatch or with the visitor pattern http://www.codeproject.com/Articles/7360/MultiMethods-in-C-Finding-a-complete-solution | |
Re: > I'd like to use std::tr1::regex You have `int _tmain(int argc, _TCHAR* argv[])`; so presumably you are using the Microsoft compiler. If it is a recent version (2010 or later), use `std::regex` instead. > I was expecting all values between % and % The regular expression `%(.*?)%` consumes the terminating … | |
Re: > tellg() in my code as the function is not supported on the desired hardware. What hardware? A `std::istringstream` holds a `std::stringbuf` and it does not use anything other than memory allocated with the standard allocator. Have you tried printing out the result returned by `tellg()` on the string stream? | |
Re: All this is (conforming) C++: struct A { // http://www.stroustrup.com/C++11FAQ.html#default // http://www.stroustrup.com/C++11FAQ.html#constexpr constexpr A() = default ; // x == 0, y == 0 constexpr explicit A( int x ) : x(x) {} // A::x==x A::y==0 A( int x, int y ) { A::x = x ; this->y = y … | |
Re: > Are they compiled separately then linked? Yes. The linking may be done either statically or at load/run time from a .dll or .so | |
Re: > I'm interested in sorting a standard container called say 'first_container' via another container which has iterators pointing to the first container. An indirect sort is useful in many situations * a sequence is immutable, but we want a sorted view of the sequence * we want to access the … | |
Re: > string::const_reverse_iterator rit = s.rbegin(); > This should be outside the loop(just before the loop) Yes. And you need not go all the way to `end()`; upto the middle of the string would suffice. Which would make the code equivalent to: bool is_palindrome( const std::string& str ) { return std::equal( … | |
Re: The linker can't find the library files. You need to add one or more **-L<path to library files>** to the link command http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Directory-Options.html#Directory-Options For example: **-LC:\MinGW\lib** | |
Re: > Main part of my project is to capture and parse all incoming and outgoing network traffic on the fly. Do you think that merits a performance concern? It certainly does. Bursts in network traffic are difficult to predict and difficult to simulate with any kind of accuracy. Nevertheless, performance … | |
Re: > So my question is, why is it crashing? container_Student_info::iterator iter = students.begin() ; while(iter!=students.end()) { if(fgrade(*iter)) { // .... } else { it = students.begin(); students.insert(it, *iter) ; // the iterator 'iter' is no longer valid // because we have modified (added a new item into) the container // … | |
Re: > I pretty much get what was posted (need to look up sprintf), but the code below gives me the error that "fname, MAX_FILE_NAME_LENGTH, and strlen" Why have you started messing around with all this stuff? Your origininal idea was far superior; just that you made a careless typo. Fix … | |
Re: > Each constructor and destructor gets called each time the loop is executed... If this is what you want, arkoenig has already given you the solution. > The purpose is to create a brand new object each time the loop is executed for as long as the loop runs. Once … | |
Re: > I have a string and in it there is a character I want to remove. > What is the best way to remove it? Remove char at position **pos** in string **str** `str.erase( pos, 1 ) ;` or `str.erase( str.begin() + pos ) ;` or `str = str.substr(0,pos) + … | |
Re: Use `std::sort()` and `std::unique()` in <algorithm> #include <algorithm> #include <iostream> int main() { int a[] = { 0, 1, 0, 2, 3, 4, 3, 3, 5, 2 } ; enum { SIZE = sizeof(a) / sizeof(*a) } ; std::sort( a, a+SIZE ) ; const int size_unique = std::unique( a, a+SIZE … | |
Re: See the posts by arkoenig (towards the end) in this thread: http://www.daniweb.com/software-development/cpp/threads/360216/c-value-initialization | |
Re: > The point of the exercise is to use list throughout rather than vector. Yes; the point of the exercise is to understand the difference between using a sequence container like `std::vector<>` that provides random access to its values and one like `std::list<>` that does not. double median( list<double> vec … | |
Re: Use a library to do this. **libcurl** would be the default choice. http://curl.haxx.se/libcurl/ Sample source code: http://curl.haxx.se/libcurl/c/ftpget.html Tutorial: http://curl.haxx.se/libcurl/c/libcurl-tutorial.html | |
Re: See: http://www.daniweb.com/software-development/cpp/threads/392114/could-i-find-a-replacement-of-lokitypelist-from-boost | |
Re: > So,what should I do to solve this problem? Write your own TRACE(). #include <cstdarg> #include <cstdio> #include <windows.h> #include <iostream> void TRACE( const char* format, ... ) { va_list args ; va_start( args, format ) ; enum { MAX_MESSAGE_SIZE = 4192 } ; char msg[ MAX_MESSAGE_SIZE ] ; std::vsnprintf( … | |
Re: if your idea was to have a code sample which will help you understand how virtual function calls are implemented by the microsoft compiler: [code=c++]#include <iostream> #if defined(_MSC_VER) && (_MSC_VER >= 1200) && defined(_M_IX86) struct A { // __stdcall, args passed on stack, 'this' is the first arg virtual void … | |
Re: First, is this the "best" way to tackle the chat problem? no. it is unlikely that someone would want to set up a chat between two processes on the same machine, sharing stdin and stdout between them. write two separate programs; the server and the client. which can be run … | |
Re: after exiting from main, the following actions are performed: a. call destructors of objects with static storage b. call atexit functions c. deinit the C runtime library during this, it was detected that some dynamically allocated memory block is invalid. this can occur due to a variety of reasons; but … | |
Re: arkoenig wrote: > I would think that if you replace the type std::pair<std::string, unsigned long> in > lines 7 and 23 by std::pair<const std::string, unsigned long>, it ought to work. > At least I can't think immediately of any reason it shouldn't. I had always thought that this error (given … | |
Re: Use the standard smart pointers, perhaps? See: [url]http://www.devx.com/cplus/10MinuteSolution/39071/1954[/url] and: [url]http://www.devx.com/cplus/10MinuteSolution/28347/0/page/1[/url] | |
Re: > Of course I could add pure virtual functions in ImageBase and implement them in Image, > but then I will be using a modified version of the library, which is huge headaches for users. > Is there a way to do this without touching ImageBase? If the only issue … | |
Re: [CODE]int otherFunc(void) { float [COLOR="Red"]foo[/COLOR] = .5f; //assume widget has been created g_signal_connect(G_OBJECT(widget), "clicked", G_CALLBACK(kitty), (gpointer)[COLOR="Red"]&foo[/COLOR]); }[/CODE] Wouldn't this [B]foo[/B] be destroyed by the time the event handler [B]kitty[/B] is called? Also, do read up on comparing floating point values. [url]http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm[/url] | |
Re: http://software.intel.com/en-us/articles/intel-c-compiler-compatibility-with-microsoft-visual-c/#a_UIIDE | |
Re: Native support for rtti in C++ is minimal; type-safe down and cross casts and a run-time type identifier (which apply to only polymorphic types). This is woefully inadequate to implement an architecture using the reflection pattern. [url]http://www.vico.org/pages/PatronsDisseny/Pattern%20Reflection/index.html[/url] Since the language is statically typed, programs are not run under an interpreter … | |
Re: This would suffice:[CODE]template< typename T > void foo( const T& t ) ; template< typename T > void foo( const MyClass<T>& mc ) ;[/CODE] The partial ordering of templates involved (that is taken into account in the deduction process) would make the second template be preferred over the first for … | |
Re: If the sequence of characters in the input stream is valid (a sequence that could have been written out during output), consume all the valid characters and update the object to reflect the new values Else leave the object unchanged and set the stream to a failed state. With this … | |
Re: The IS specifies that a predicate should not assume that the dereferenced iterator yields a non-const object. Arguments should therefore be taken by reference-to-const or by value. The IS also specifies that algorithms that take function objects as arguments are permitted to copy those function objects. So in most cases, … | |
Re: > Is it possible to write a c++ compiler in c++ ? The first C++ compiler was written in C++. [url]http://www2.research.att.com/~bs/bs_faq.html#bootstrapping[/url] Clang is written in pure C++; with heavy use of C++ facilities (like STL). [url]http://clang.llvm.org/[/url] Pretty well-written code too, IMHO. | |
Re: > talk with an attorney who has some knowledge of intellectual property issues. +1 | |
Re: [B]sum+=(1/factorial(i)) ;[/B] Is integer division ok here? A more efficient way to sum up this series would be to use the recurrence relation between successive terms. [B]1/1! + 1/3! + 1/5! + ... = a<0> + a<1> + a<2> + ... a<0> = 1 ; a<1> = a<0> / (2*3), … | |
Re: See: [url]http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.genprogc%2Fdoc%2Fgenprogc%2Fwriting_reentrant_thread_safe_code.htm[/url] | |
Re: > how would i stop a user from entering a letter when they should be entering a number? There is no really portable way of doing that. What can be done is: let the user enter any set of characters, and if those do not form a valid number, ask … | |
Re: "The most effective way to increase your knowledge is to try new problems in a controlled way. Pick [I]one[/I] aspect of C++ that you haven't understood before and write a program that, aside from using that one aspect, uses only things that you have already mastered. Then do what it … | |
Re: > s this legal? (For example, can I set a GUIComponent as the return of a function and instead return a subclass?) Yes. For example: [CODE]GUIComponent* getComponent() { return new TextLabel( /* ... */ )[/CODE] is fine, provided [B]TextLabel[/B] is a derived class of [B]GUIComponent[/B]. > Why is the compiler … | |
Re: You have not opened the stream successfully - the [B]FILE*[/B] pointer was [B]NULL[/B] at the time you did an [B]fseek()[/B]. Verify that [B]fopen()[/B] returned a non-NULL pointer. (Perhaps you are using a relative path to file which is no longer correct for the project copied into a different directory). | |
Re: In lines 90-93, change[code] Decorator ( Switch * sw ) : swit ( *sw ) { swit = sw; }[/code] To[code]Decorator ( Switch * sw ) : swit ( sw ) // initialize the [B][COLOR="Red"]pointer[/COLOR][/B] swit with sw {}[/code] | |
Re: [b]N[/b] students to be given a different random ball each from a population of [B]M[/b] balls. [B]a[/B]. [B]M[/B] is not much larger than [b]N[/b] (for example 100 balls and 50 studenta): Generate a random permutation of the [B]M[/b] balls ([B]std::random_shuffle()[/B]) and assign the first ball in the permutation to the … | |
Re: > I cant seem to find anything useful on the web except adding outside libraries for this one With a conforming implementation, nothing more than the standard C++ library is needed. Something like this: [CODE]#include <thread> #include <atomic> #include <chrono> void save_file( const std::string& path, int minutes, std::atomic<bool>& keep_saving /* … |
The End.