1,247 Posted Topics
Re: [quote=jbennet;411781]yeah turbo c++ is ancient, nonstandard and unstable[/quote] completely incorrect. the current version of turbo c++ (the free version is now called 'Turbo C++ Explorer') does support standard ANSI C and ISO/IEC C++ languages and libaries. it includes the Dinkumware C++ runtime libraries and supports the Boost library. download from … | |
Re: [code=cplusplus] #include <iostream> #include <cctype> #include <cstring> #include <algorithm> using namespace std ; const char* const ranks = "A23456789TJQK ATJQK" ; struct on_rank { bool operator() ( char a, char b ) const { return strchr(ranks,a) < strchr(ranks,b) ; } }; int main() { enum { NCARDS = 5 }; … | |
Re: [quote=Ancient Dragon;410687]...you might check the boost libraries to see if it contains anything usefule.[/quote] yes, boost.iostreams could be used. [code=cplusplus] #include <iostream> #include <boost/iostreams/stream.hpp> #include <boost/iostreams/device/file_descriptor.hpp> #include <fcntl.h> // posix open #include <cassert> #include <iterator> #include <stdlib.h> // system using namespace std ; using namespace boost::iostreams ; int main() { … | |
Re: the total store of c++ functions is fixed. these are the functions which were written when the code was compiled; there is simply no way to create new functions at run time. what differentiates function objects from functions is that they are objects (variables). in principle we can do everything … | |
Re: [code]**&p == *(*&p) == *p *&*&*&x == *&*&x == *&x == x[/code] unary & is the addressof operator; unary * is the dereference operator. so [CODE]&x[/CODE] == address of x (pointer to x) [CODE]*&x [/CODE]is dereference of the pointer to x ie. dereference address of x (== x itself). | |
Re: it is a standard component of the library in c++0x see [url]http://www.open-std.org/jtc1/sc22/wg21/[/url] libstdc++ (gcc 4.30) and dinkumware std c++ library implement this natively; boost.tr1 library could be used if you have an older compiler and boost. [code=cplusplus] #include <iostream> #include <functional> int main( int argc, char** argv ) { //using … | |
Re: see: [url]http://mark.dufour.googlepages.com/home[/url] | |
Re: [code=cplusplus] #include <fstream> #include <string> #include <vector> #include <cassert> using namespace std ; int main() { const char DELIM = '>' ; const char* const file_name = "whatever" ; ifstream file( file_name ) ; assert(file) ; vector<string> names, sequences ; string line ; // skip lines till we get one … | |
Re: now that you have solved it, can you make it more efficient? ie. find the max for each row and each col by making one single pass through the elements of the array. | |
Re: 1. [B]g++ -DHAVE_CONFIG -Wall -std=c++98 -o myprogram[/B] 2. [B],/myprogram hello world[/B] in 1., the command line args are used by the c preprocessor, some are forwarded to the compiler and linker in 2., the command line args are passed to myprogram and are available as parameters passed to main | |
Re: [code=cplusplus] template <typename T> void template_function( T arg ) ; template <typename T> void function( void (*func)(T) ) { /* ... */ } // this is better, would also accept compatible functions // and function objects template <typename FN> void better_function( FN arg ) { /* ... */ } [/code] | |
Re: [quote=joeprogrammer;372921]...NetBeans...That's for Java. An entirely different programming language.[/quote] see [U][url]http://www.netbeans.org/products/cplusplus/[/url][/U] it is lighter on resources than eclipse+cdt, and would be a good option for a c++ IDE, particularly on a unix/linux platform. | |
Re: it is fine if your idea is just test out your understanding of templates, functors and inheritance. however, functors (aka function objects) are usually not implemented as object oriented types for a variety of reasons. [code=cplusplus] template <typename T> struct sort_base { virtual void operator()( T array[], const int size … | |
Re: [code=cplusplus] ifstream file("a:\\crypnums.txt"); vector<int> numbers ; int i ; while( file >> i ) numbers.push_back(i) ; assert( file.eof() ) ; [/code] or [code=cplusplus] ifstream file("a:\\crypnums.txt"); vector<int> numbers ; istream_iterator<int> begin(file), end ; copy( begin, end, back_inserter(numbers) ) ; assert( file.eof() ) ; [/code] both assume that the integers are seperated … | |
Re: a. it is probably wiser not to hold the seperator string (_sep) as a pointer; this might get us into trouble if a temporary was passed as the second constructor arg b. the hard coded assumption that CHAR_BITS==8 should be done away with c. we could reuse the functionality available … | |
Re: [quote=sowmi;395444]...I have 100 commands and whenever the commands are pressed the corresponding function + arguements...[/quote] it is much more flexible to represent functions as objects . this would allow free functions, function objects and member functions to be treated polymorphically. also, since these are objects, they can support operations (eg.bind). … | |
Re: > the assembly output doesn't show me the code generated for C++'s strlen(), just my strlen() and xstrlen(). the microsoft C++ compiler recognizes and directly inserts optimized inline code for several functions (including strlen). functions like strlen in the Standard C library are available in both intrinsic and non-intrinsic forms. … | |
Re: if the enums have consecutive integral values (as in this case), we can increment by adding one to the value. [code=cplusplus] #include <iostream> int main() { enum level { FRESHMAN=0, SOPHMORE=1, JUNIOR=2, SENIOR=3 } ; const char* const literal_level[] = { "FRESHMAN", "SOPHMORE", "JUNIOR", "SENIOR" } ; for( level lev … | |
Re: the server will bind to an address and start listening on it. the client socket is usually dynamically bound and tries to connect to the socket at the address the server has bound. so the port the client tries to connect to should be the same as the one the … | |
Re: include winsock2.h link to ws2_32.lib needs ws2_32.dll | |
Re: [code=cplusplus] const char* const months = "*ABCDEFGHIJKL" ; inline char month_to_code( int m ) { assert( m>0 && m<13 ) ; return months[ m ] ; } inline int code_to_month( char c ) { const char* p = strchr( months, toupper(c) ) ; assert( p!=0 && p!=months ) ; return … | |
Re: if you are not alowed to reorder the original sequence, but are allowed to use auxiliary storage [code=cplusplus] #include <vector> #include <set> #include <iostream> #include <string> using namespace std; template< typename CNTR > void print_duplicates( const CNTR& cntr ) { set< typename CNTR::value_type > unique ; for( size_t i=0 ; … | |
Re: [quote=Nichito;358676]nonetheless, i found out that clock() works different depending on which compiler you are working... 4 example... in dev c++, i measured clock measured 1/1000... but turbo c++ measured 1/20... the thing is... i don't know why...[/quote] [code=c] clock_t start, end; double cpu_time_used; start = clock(); /* whatever */ end … | |
Re: [code=cplusplus] #include <vector> #include <algorithm> using namespace std ; int main() { vector<int> cntr( 20U, 7 ) ; int* array = new int [ cntr.size() ] ; typedef vector<int>::iterator iterator ; int x = 0 ; for( iterator it = cntr.begin() ; it != cntr.end() ; ++it, ++x ) { … | |
Re: a constructor which [B]a.[/B] can be called with one arg[B] b.[/B] is not marked explicit is also an implicit conversion operator. [code=cplusplus] struct A{}; struct C {}; struct B { B(const A&) {} explicit B(const C& ) {} }; A a ; C c ; B b = a ; … | |
Re: except in a trivial situation, where the compiler can optimize away the storage, a reference is stored in memory as an address. so for, [inlinecode]struct A { double& ref ; A(double&d) : ref(d) {} };[/inlinecode] sizeof(A) == sizeof(double*) when a reference is passed to a function, what is passed is … | |
Re: [code=cplusplus] #include <vector> #include <boost/tokenizer.hpp> #include <string> #include <vector> #include <iostream> using namespace std; using namespace boost; int main() { string str = "The boost tokenizer library provides a flexible " "and easy to use way to break of a string or other " "character sequence into a series of … | |
Re: members or base class sub-objects cannot be initialized inside the body of the constructor; they can only be assigned to. initialization is always before the body of the constructor executes. if not initialized expliciltly using colon initialization, the implementation will provide default initialization if available. for any member which does … | |
Re: you must be using a microsoft compiler (or a compiler with abi compatibility with the microsoft compiler). if the destructor is virtual, an entry needs to be made for the destructor in the vtbl of the class. for [inlinecode]delete ptr_abc[/inlinecode], two things need to happen. a. the correct destructor must … | |
Re: a sequence container can also be initialized with a sequence identified by a pair of iterators. [code=cplusplus] char cstr[] = "abcdefghijkl" ; std::list<int> list2( cstr, cstr+sizeof(cstr) ) ; [/code] in c++0x, the following would be another way: [code=cplusplus] std::list<int> list5 = { 23, 6, 57, 575, 7575, 75 }; // … ![]() | |
Re: line 4: LRESULT CALLBACK WindowProcedure (HWND hwnd, [COLOR=red]UINT 5 message[/COLOR], WPARAM wParam, LPARAM lParam); line 9: _pAE = new AppEngine(HINSTANCE, LPSTR, LPSTR, WORD, [COLOR=red]10 WORD[/COLOR], int, int); these are the errors. the compiler/ide you are using seems to emit very poor error messages. | |
Re: for controls other than buttons, you could handle the WM_CTLCOLORXXX notification; eg. WM_CTLCOLOREDIT for an edit control. for buttons, the button needs to be an owner-drawn button; for such a button the system sends the parent window a WM_DRAWITEM message. see: [URL]http://msdn2.microsoft.com/en-us/library/ms673346.aspx[/URL] | |
Re: [quote=~s.o.s~;371983]... I still vote for Python or Java.[/quote] glad to note that you dropped perl from the list. a 'write once, read never' language is probably not good for anyone. smalltalk would rank very high among good languages for beginners; it is arguably the best language for beginners. | |
Re: see [url]http://www.cprogramming.com/tutorial/initialization-lists-c++.html[/url] | |
Re: [code=cplusplus] if( std::find( alist.begin(), alist.end(), x ) != alist.end() ) { /* do this */ }[/code] | |
Re: the file you are trying to compile it is a C (not C++) file. compile that with gcc, not g++. in your C++ code include the header as follows: [code=cplusplus]extern "C" { #include "whatever.h" }[/code] | |
Re: [quote=Salem;381245]It's just simple maths [code] void process ( int a, int b ) { char var[10]; process( 0, 0 ); } [/code] You have a char array, so that's 10 bytes. Two integers - say 4 bytes each (total 8). Each call has a fixed overhead of several bytes (say … | |
Re: a. correct your existing code so that it will compile without errors; test it. b. convert the recursive algorithm to a tail-recursive form. c. convert the tail-recursive implementation to an iterative one. for steps b. and c., see: [url]http://en.wikipedia.org/wiki/Tail_recursion[/url] [url]http://www.nist.gov/dads/HTML/tailrecursn.html[/url] | |
Re: [quote=thekashyap;381268]...modify a const by casting[/quote] really you should not. a constant whose value is known at compile time a. may (would) be placed into memory with read-only access by the compiler if it has a static storage class. b. the compiler can (should) treat such a contant as if it … | |
Re: [code=cplusplus] class D { // ... D operator- ( const D& d2 ) const; // ... }; D D::operator- ( const D& d2 ) const { // ... [/code] would also make your code const-correct. | |
Re: [URL]http://www.freeprogrammingresources.com/cppbooks.html[/URL] [URL]http://www.thefreecountry.com/documentation/onlinecpp.shtml[/URL] [URL]http://www.linuxselfhelp.com/HOWTO/C++Programming-HOWTO-13.html[/URL] Thinking in C++ vols 1 & 2 (2nd ed) by bruce eckel is probably the best online book for beginners. [B] [/B] | |
Re: for standard C++ (ISO/IEC 1998,2003), the project type you would use is one of [B]Win32 Console Application[/B] / [B]Win32 library[/B] [B]/ General MakeFile Project[/B]. if you are new to Visual Studio 2005, start with a [B]Win32 Console Application[/B] project. and in the project settings, disable microsoft language extensions. ( either … | |
Re: the issuse is that your program is written in C++/CLI, the dll is in pure C++. to use the dll, you would need to use p-invoke. you could [code=cplusplus] #pragma unmanaged #include <dll header files> #pragma managed [/code] you would also need to make modifications in your project settings (eg. … | |
Re: you could use the boost tokenizer library. here are a few links: [URL]http://www.boost.org/libs/tokenizer/index.html[/URL] [URL]http://www-eleves-isia.cma.fr/documentation/BoostDoc/boost_1_29_0/libs/tokenizer/examples.cpp[/URL] you could also use the boost string algorithms library (if the file is read line by line into a string) [URL]http://www.boost.org/doc/html/string_algo.html[/URL] | |
Re: 9/5 is an integer expression (==1). use float fahrenheit = celsius * float(9)/5 + 32 ; it would be better to use doubles instead of floats unless there is an externally imposed constraint. salem, didn't see your post! | |
Re: [code=cplusplus] #include <boost/lexical_cast.hpp> int main( int argc, char* argv[] ) { if( argc> 2 ) { try { int value = boost::lexical_cast<int>( argv[2] ) ; // use value } catch( const boost::bad_lexical_cast& ) { // cast error } } [/code] this is part of the proposal for c++0x (in TR2) … | |
Re: here are two links that may be helpful: [URL]http://www.codeproject.com/cs/media/Motion_Detection.asp[/URL] [URL]http://www.lavrsen.dk/twiki/bin/view/Motion/WebHome[/URL] | |
Re: windows: see [URL]http://msdn2.microsoft.com/en-us/library/aa394587.aspx[/URL] apple: see [URL]http://developer.apple.com/technotes/tn/tn1103.html#TNTAG3[/URL] bsd: use dmidecode (in ports). | |
Re: [url]http://users.actcom.co.il/~choo/lupg/tutorials/multi-thread/multi-thread.html[/url] [url]http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html[/url] [url]http://www.codeproject.com/useritems/MultithreadingTutorial.asp[/url] you would fing several more if you google on: threading C tutorial |
The End.