1,247 Posted Topics
Re: >> // will not work - Save() wants an IStream!!! >> Gdiplus :: status hr = image.Save (pFile, &encoderClsid); [code=cplusplus]// ...... IStream* pstm ; assert( CreateStreamOnHGlobal( 0, TRUE, &pstm ) >= 0 ) ; Gdiplus::Status hr = image.Save( pstm, &encoderClsid ) ; STATSTG stat ; assert( pstm->Stat( &stat, STATFLAG_NONAME ) … | |
Re: >> ... depending on the value of variable "var"at runtime. Also i know it can be done using template ... an option would be to use run-time polymorphism. [code]class base { virtual ~base() = 0 {} }; class Class1 : public base {} ; class class2 : public base {} … | |
Re: [url]http://www.codeguru.com/forum/archive/index.php/t-84003.html[/url] | |
Re: >> and then for the macro call I could say ... and the test would be done inline, >> but I can't do that with a function, because the arguement is evaluated before it's passed: use a function object (or a pointer to a function; not as flexible or efficient) … ![]() | |
Re: add this too. you have overloaded operator new, but not overloaded operator delete. so [inlinecode]delete whatever[/inlinecode] will call the wrong operator delete; the results will not be pretty. | |
Re: you could use the following compiler switches. [B]/C[/B] preserve comments during preprocessing. [B]/E[/B] copy preprocessor output to standard output (with #line) [B]/EP[/B] copy preprocessor output to standard output (without #line) [B]/P[/B] write preprocessor output to a file. To set this programmatically, use the [B]VCCLCompilerTool[/B] class. [B]VCCLCompilerTool::GeneratePreprocessedFile[/B] property provides the same … | |
Re: >> .. really mad. It,s not displays as a binary code, I mean bunch of zeros and ones. if all you want to do is display the contents of a file as a sequence of bits (i presume that is what you mean by bunch of zeros and ones), [code=cplusplus]#include … | |
Re: for merely notifying another process that some event has occurred, you could use an event object. [URL]http://msdn2.microsoft.com/en-us/library/ms682655.aspx[/URL] [URL]http://www.codeproject.com/csharp/interopevents.asp[/URL] to also pass additional information, you would need to use an ipc mechanism. [URL]http://msdn2.microsoft.com/en-us/library/aa365574.aspx[/URL] | |
Re: [url]http://www.linuxhacker.at/socketxx[/url] [url]http://www.boost.org/doc/html/thread.html[/url] | |
Re: create an Xcode C++ tool project. [url]http://www.meandmark.com/xcodeintro.pdf[/url] | |
Re: >> what is the corresponding standard lib function of Win32's WideCharToMultiByte()? there are two options available; use the ctype<> facet or the codecvt<> facet. the following example uses ctype<> for conversion. [code=cplusplus]#include <locale> #include <iostream> #include <string> #include <sstream> using namespace std ; wstring widen( const string& str, const locale& … | |
Re: [url]http://en.wikipedia.org/wiki/List_of_SIP_software[/url] | |
there seems to be nothing much happening in the c++ forum today. so here is something to chew on for programmers who are relatively new to templates: c++ can also be used as a metalanguage. [code=cplusplus]#include <iostream> using namespace std ; // compile-time computation of fibonacci numbers template < int … | |
Re: for simple round-robin scheduling, add the jobs to the back of a simple queue (use a std::queue for this). to schedule a job, pick the one at the front of the queue. if a job blocks (goes into a wait state) or its time-slice is over, put it back (at … | |
Re: >> I took a course in JAVA and learned about exceptions...I'm not sure how to throw and catch in C++. the fundamental difference is the use of the 'resource acquisition is initialization' technique in resource management. the c++ philosophy is a. error handling code must be clearly seperate from normal … | |
Re: and here are some books. 1. Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides (Addison-Wesley Professional) 2. Design Patterns Explained: A New Perspective on Object-Oriented Design (2nd Edition) by Alan Shalloway, James Trott (Addison-Wesley Professional) 3. Refactoring: Improving the Design of Existing … | |
Re: you would be better off using icc for processor-specific optimizations. even without processor-specific optimizations, icc generates better optimized code than vc++ 8; and it blows gcc away. [URL]http://www.intel.com/cd/software/products/asmo-na/eng/276615.htm[/URL] | |
Re: using boost.spirit may be much easier: [URL]http://www.boost.org/libs/spirit/doc/quick_start.html[/URL] [code=cpp]#include <boost/spirit/core.hpp> #include <iostream> #include <string> #include <vector> #include <algorithm> #include <boost/assign.hpp> using namespace std ; using namespace boost ; using namespace boost::spirit ; using namespace boost::assign ; struct parse_it { void operator() ( const string& str ) const { vector<string> tokens ; … | |
Re: here is a safer version which performs sanity checks [code=cplusplus]#include <sstream> #include <limits> #include <cassert> // returns 0 on overflow template< typename T > inline T join( T a, T b ) { typedef std::numeric_limits<T> limits_type ; assert( limits_type::is_specialized && limits_type::is_integer ) ; assert( !limits_type::is_signed || ( b>=0 ) ) … | |
Re: main is a function written by the user, but it is special in several ways. as per ISO/IEC 14882(E): 3.6.1-1a program shall contain a global function called main, which is the designated start of the program. ... 3.6.1-2 an implementation shall not predefine the main function. this function shall not … | |
Re: [CODE]printf((char *)&num);[/CODE] is clearly an error; you are casting a double* to a char* (which is incorrect). unpleasant consequences would be the norm if you do such things. in C, to print out a double value, use [CODE]printf( "%f", num ) ;[/CODE] instead. atof is to be shunned; it has … | |
Re: you can repesent a graph as an adjacency matrix. [URL="http://www.cs.usask.ca/resources/tutorials/csconcepts/1999_8/tutorial/beginner/matrices/matrix.html"]http://www.cs.usask.ca/resources/tutorials/csconcepts/1999_8/tutorial/beginner/matrices/matrix.html [/URL] [URL="http://www.cs.usask.ca/resources/tutorials/csconcepts/1999_8/tutorial/beginner/matrices/matrix.html"]using the specialization vector<bool> would take only one bit per matrix element, so large graphs can be accommodated. (not withstanding my efforts, the daniweb formatter refuses to believe that this sentence is not a url)[/URL] [code=cplusplus]#include <iostream> #include <vector> … | |
Re: [url]http://www-128.ibm.com/developerworks/linux/library/l-ipc2lin3.html[/url] | |
Re: to put the machine into suspend/hibernate state, use SetSuspendState [url]http://msdn2.microsoft.com/en-us/library/Aa373201.aspx[/url] to wakeup from suspend/hibernate, use SetWaitableTimer [url]http://msdn2.microsoft.com/en-us/library/ms686289.aspx[/url] with the last parameter (fResume) as TRUE and have a thread wait for the timer to be signalled or specify an APC to be called. note: to wake up from hibernate, hardware support … | |
Re: if you are interested in only an approximate value, you could use a type like double for computing the result. for example, a long double can hold very large values, but precision is limited (on my compiler, the mantissa is accurate upto 15 decimal digits). [code=cplusplus]#include <limits> #include <iostream> #include … ![]() | |
Re: dragon's algorithm does work. here is a version which a. uses isspace (handle all char sets) b. uses erase instead of extract substrings and concatenate (little more efficient). c. continues from the next char while repeatedly searching for whitespaces (again, little more efficient) [code=cplusplus]void remove_ws( vector<string>& vertex ) { int … | |
Re: > search the string (file name ) and read its data (file position) with a good speed. The requirement is that I have to search for 869 files. the number of files are quite small; if you have to do this search more than once, it would be faster to … | |
Re: bsd: [URL="http://people.freebsd.org/%7Ekientzle/libarchive/"]http://people.freebsd.org/~kientzle/libarchive/[/URL] as root, cd /usr/ports/archivers/libarchive && make install clean windows: [URL]http://gnuwin32.sourceforge.net/packages/libarchive.htm[/URL] you would need to fetch the setup program & verify the MD5 checksum manually | |
Re: > i think im going to ask my IT teacher ... but he sucks why don't you ask this person? [url]http://www.research.att.com/~bs/bs_faq2.html#void-main[/url] | |
Re: > am planning to write a simple implementation of T9 , as seen in nokia phones. Could someone suggest an efficient way to go about this ?? [url]http://en.wikipedia.org/wiki/Trie[/url] [url]http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Tree/PATRICIA/[/url] ![]() | |
Re: [code=cplusplus]struct singleton { // return a reference, not a pointer. the problem with returning // a pointer is that a caller might be tempted to call delete on it // returning an auto_ptr<> to a singleton is ruled out; // it's (or it's copy's) destructor *will* call delete on the … | |
Re: > I know the if statement would be a better choice but I must you use the switch for an assignment would this make your teacher happy? [code=cplusplus]enum { LESS_THAN_10000, NOT_LESS_THAN_10000 }; int to_be_used_in_switch = sales < 100000.0 ? LESS_THAN_10000 : NOT_LESS_THAN_10000 ; switch( to_be_used_in_switch ) { case LESS_THAN_10000: /* … | |
Re: [url]http://www.troubleshooters.com/codecorn/primenumbers/primenumbers.htm[/url] | |
Re: (1*n)+(2*n)+(3*n)...(n*n) == (1+2+3+..+n)*n == (n+1)/2*n*n | |
Re: using far pointers you are still limited by 64K memory regions; its just that, that region can be outside your current CS or DS, and you can have many such regions. pointer arithmetic on far pointers do not modify the segment portion of the pointer, only its offset (modulo 64K … | |
Re: > Because the code must read the digit one by one as individual characters(CHAR values)and convert them to numeric form. or you can read the literal digits into a string; this would be easier. > And you know C++ uses ASCII code for a character when it appears in an … | |
Re: see: [url]http://www.daniweb.com/forums/thread85114.html[/url] note: [INLINECODE]cout << "size of file: " << sizeof(parent) << endl; //size of the parent.txt file, for test purpose[/INLINECODE]will not give you the size of the file on disk; sizeof(parent) gives you the amount of memory that the variable[I] parent[/I] takes ( as a multiple of sizeof(char) ) ![]() | |
Re: you do not have to close and then reopen the file; [inlinecode]inData.clear() ; inData.seekg(0) ;[/inlinecode] is more efficient. > I need the number of lines before I can correctly do the other stuff. you do not; use a vector instead of a c-style array: [code=cplusplus]#include <iostream> #include <fstream> #include <string> … | |
Re: [code=cplusplus]#include <iostream> #include <string> using namespace std ; int main() { string str ; getline( cin, str ) ; cout << str << '\n' ; cout << oct << showbase ; for( size_t i=0 ; i<str.size() ; ++i ) cout << int( str[i] ) << ' ' ; cout << … | |
Re: [code=cplusplus]#include <algorithm> #include <vector> #include <iostream> #include <ctime> #include <iterator> #include <boost/random.hpp> #include <limits> using namespace std ; using namespace boost ; inline double elapsed_msecs( clock_t start, clock_t end ) { return double( end - start ) * 1000.0 / CLOCKS_PER_SEC ; } int main() { // choose a reasonably … | |
Re: [quote=satya.vijai;417028]...I thought of doing like, 1. get the file size 2. create a char* and allocate the size of file size 3. copying the entire file into a string buffer using Readfile() API... but I think this is not ideal, so is there any other way to do it better.. … | |
Re: dynamic scoping is almost never used these days. with dynamic scoping, a variable reference is bound to the most recent instance of that variable on the call stack. for example: [code=cplusplus]#ifdef this_should_not_compile void b() ; void c() ; void a() { int x = 24 ; int y = 32 … | |
Re: you cannot apply a dynamic_cast on a void* to get a non void pointer. except in a trivial case, in dynamic_cast<T>(v), v should be a pointer to or an lvalue of a polymorphic type. if T is a (cv qualified) void* , and v is a pointer to a polymorphic … | |
Re: [inlinecode]// .... while(! infile.eof()) { infile>>sentense; continue; count+=letter; cout<<"The letter a repeated"<<count<<"times(s)"<<endl; } // ... [/inlinecode] the continue does nothing (other than perhaps satisfy your teacher) and the statements following it in the loop would be silently ignored by the compiler during code generation. you should change it to if( … | |
Re: ZN10FindDialogC2EP7QWidget is the result of the c++ compiler embedding type/namespace information in names (this is called name decoration or name mangling) . see: [url]http://en.wikipedia.org/wiki/Name_mangling#Complex_example[/url] for an example. you have probably inherited virtual functions from the base class QDialog and i think you are not linking to the library that contains … | |
Re: Dragon's suggestion of SystemTimeToVariantTime is the easiest way, but might give you inaccurate resuts if you need sub-second resolution for time. see: [URL]http://support.microsoft.com/kb/297463[/URL] if you need millisecond resolution, more work is required [code=cplusplus]inline unsigned __int64 to_integral( const SYSTEMTIME& st ) { FILETIME ft ; SystemTimeToFileTime( &st, &ft ) ; ULARGE_INTEGER … | |
Re: [quote=khalidxa;412982]... when I run the program, it returns a memory address. I want it to return the value for the array.[/quote] array names 'decay' into pointers (addresses); this is fundamental to their use in C and C++. to return an array by value, you could either wrap a structure around … | |
Re: if it is c++, using boost.tokenizer would be the easiest way. [code=cplusplus]#include <iostream> #include <fstream> #include <boost/tokenizer.hpp> #include <string> #include <vector> #include <iterator> #include <boost/lexical_cast.hpp> using namespace std; using namespace boost; struct abc { explicit abc( const string& line ) ; string x ; string y ; int z ; … | |
Re: [code=cplusplus]#include <iostream> #include <limits> using namespace std ; inline double get_double() { double value ; if( cin >> value ) return value ; cout << "you have to enter a number!\n" ; cin.clear() ; cin.ignore( numeric_limits<streamsize>::max(), '\n' ) ; return get_double() ; }[/code] | |
Re: [code=cplusplus]// ISO/IEC 10646:2003(E) is available for free download from http://standards.iso.org/ittf/PubliclyAvailableStandards/c039921_ISO_IEC_10646_2003(E).zip // unicode 5.0 has the same character repertoire as // ISO/IEC 10646:2003 with Amendments 1 and 2 applied. // in g++ and microsoft c++, wchar_t is unicode 5.0. using either, #include <iostream> #include <string> using namespace std ; int main() … |
The End.