1,247 Posted Topics
Re: [code=c++]struct Properties { int mint; int maxt; int medt; Properties( int a, b, c ) : mint(a), maxt(b), medt(c) {} }; typedef std::map < std::string, Properties > ProcessMap; bool is_there( const ProcessMap& pmap, const std::string& pname ) { return pmap.find(pname) != pmap.end() ; } void insert( ProcessMap& pmap, const std::string& … | |
Re: one of the great classics of c++ deals with this topic in depth; 'Large-Scale C++ Software Design' by John Lakos. [url]http://www.amazon.com/Large-Scale-Software-Design-John-Lakos/dp/0201633620[/url] 'More C++ Gems' by Stanley Lippman (F), Robert C. Martin (E) [url]http://www.amazon.com/More-Gems-SIGS-Reference-Library/dp/0521786185/ref=sid_dp_dp/002-1745891-8300801[/url] has three articles by John Lakos. these are a compact version of his seminal work. note: the … | |
Re: > I think multiple threads is a bit beyond my experience... it would be easier to use a console input buffer and wait for it to be signalled. [code=c++]#include <iostream> #include <iomanip> #include <windows.h> using namespace std ; int main() { HANDLE input = CreateFileA( "CONIN$", GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, … | |
Re: > I don't want any CRT in my application do not use anything from the library that rquires CRT to be initialized. no malloc or new, no printf or streams, no statics requiring dynamic initialization or having non-trivial destructors, no atexit etc. and write your own entry-point function. here is … | |
Re: [code]// ... for (i=0;i<3;i++) { cout<<"Name:"; [COLOR="Red"]cin >> ws ;[/COLOR] // eat up whitespaces that may be left in the buffer // or cin.ignore cin.getline(people[i].name, 20);//<--should be ok now cout<<"HC:"; cin>>people[i].hc; // you will still have problems if the user // enters non integer values here. or if the user … | |
Re: [QUOTE]The int returned by main() is a way for a program to return a value to "the system" that invokes it. On systems that doesn't provide such a facility the return value is ignored, but that doesn't make "void main()" legal C++ or legal C. [/QUOTE] - stroustrup on systems … | |
Re: what you seem to be computing is the value of 22/7 to a number of decimal digits. it is an upper limit on the value of pi [B]3 + 10/71 < π < 3 + 1/7[/B] (archemedis). for calculating the value of pi, see [url]http://en.wikipedia.org/wiki/Pi#Calculating_.CF.80[/url] | |
Re: > I want to make a program with a max function taking any number of type double and returns the greatest of them for a small number of arguments (upto about seven or so), you could use overloaded function names. [code=c++]#include <iostream> #include <algorithm> template< typename T > inline const … | |
Re: the easiest, least error-prone and the fastest way to copy an entire stream is this: [B]output_stream << input_stream.rdbuf() ;[/B]. if you are writing a utility like this, error messages are conventionally sent to [B]cerr[/B] (not [B]cout[/B]). [code=c++]#include <iostream> #include <fstream> using namespace std ; int main( int argc, char** argv … | |
Re: [code]vector < map < int , char * > > bank; bank . reserve ( 10 ); if ( bank [ 0 ] [ 0 ] == "a" ) //Memory access error[/code] this code has *two* problems. one: [B]bank[0][/B] is invalid; the vector is empty. there is no [B]bank[0][/B]. two: … | |
Re: > how can i make a new file and acces it from a class object? to make a file and access it: [code=c++]#include <iostream> #include <fstream> #include <string> using namespace std ; int main() { const char* const file_name = "/tmp/my_newfile" ; // make a new file { ofstream file(file_name) … | |
Re: here are a few utilities in bsd ports. >cat /usr/ports/textproc/rtfreader/pkg-descr RTF is the Microsoft Richtext Format, a more portable, mostly-ASCII formatting language that is exported by word processors like MS Word. These files generally have the extension .rtf, but occassionally have .doc extensions as well. This parser is from the … | |
Re: > What is best, linked lists or hash tables? depends on what your requirement is. a list is a sequence container, used to keep a collection of elements. hash tables are associative containers, used for keeping a collection of key-value pairs with support for lookup on key. > Is it … | |
Re: > is there any way that i can add up all the values in a multiplication table? you can do this in your mind [code]1*N + 2*N + 3*N + .... + (N-1)*N + N*N == (1+2+3+...+(N-1)+N) * N == ( ( N * (N+1) ) / 2 ) * … | |
Re: > to determine whether an array is sorted or not go through the array element by element from the beginning. if the element that you currently look at is smaller(as per the sort criterion) than the one you had just looked at before this, the array is not sorted. if … | |
Re: to get the command line elements, use the args passed to main: [code=c++]int main( int argc, char** argv ) { copy( argv+1, argv+argc, ostream_iterator<const char*>(cout,"\n") ) ; }[/code] to read a file line by line, use [B]::getline[/B] [code=c++]int main( int argc, char** argv ) { ifstream file(__FILE__) ; string line … | |
Re: this would be less error-prone [code=c++] if(line == "abcd 2 4 6 8 10 1 3 5 7 9") { istringstream stm(line) ; string eaten ; stm >> eaten ; int number ; while( stm >> number ) myList.push_back(number); }[/code] | |
Re: > The error seems to happen after the program is done with EVERYTHING. for a general discussion of what this error means (buffer overrun), see [url]http://msdn2.microsoft.com/en-us/library/Aa289171(VS.71).aspx[/url] | |
Re: why don't you use this hint that your instructor has given you? it seems to be the simplest way to implement TMoney: > Hint: we would suggest storing the whole amount as an amount of cents. In this case you will > keep $1.20 as 120 and you will use … | |
![]() | Re: [url]http://en.wikipedia.org/wiki/Bubble_sort[/url] |
Re: [url]http://update.eclipse.org/downloads/drops/R-3.3-200706251500/download.php?dropFile=eclipse-SDK-3.3-solaris-gtk.zip[/url] [url]http://update.eclipse.org/downloads/drops/R-3.3-200706251500/index.php[/url] | |
Re: i don't know anything about [B]oapiGetFocusShipAirspeedVector,[/B] but the code is incorrect unless the pointer is passed by reference [B]and[/B] the library allocates memory for VECTOR3. (this is very unlikely). [CODE]// incorrect unless the function is declared as // return_type oapiGetFocusShipAirspeedVector(VECTOR3*&) ; VECTOR3 *speedvec; // first we declare our vector oapiGetFocusShipAirspeedVector(speedvec);//then … | |
Re: to compile c++ code, use g++ (not gcc). eg. [CODE]>g++ -Wall -std=c++98 -pedantic -Werror expre_Shift_Operators.cpp -o expre_Shift_Operators.exe[/CODE] > I'm still a bit confused as where to implement them nowhere, unless you encounter a situation where you absolutely cannot do without them. | |
Re: [CODE]template <class T, int SIZE> class Graph { bool AddVertex(T Data) ; // ... }; template <class T, int SIZE> bool Graph<T, SIZE>::AddVertex(T Data) { // ... } [/CODE] | |
Re: on this page [url]http://msdn2.microsoft.com/en-us/express/aa975050.aspx[/url] go to the visual c++ 2005 express icon and choose the language from the 'select a language' control. if the download does not start, put the entry in the 'select a language' control back to 'select your language' and then reselect 'english' once again. this worked … | |
Re: unfortunately, there is no portable way to discard unread characters from a stdio input stream. a language library technique would not necessarily be sufficient for this since unread characters can also accumulate in buffers other than the c++ streambuf (OS-level input buffers). to actively discard typed-ahead input (perhaps in anticipation … | |
Re: > functions are defined in 5 different headers what do these look like? > a header allheaders.h which include all the header files in what order? | |
Re: converting ascii text files is trivial; you have a variety of tools. eg. tr, perl, awk, vi etc.in fact anything that can replace a cr-lf sequence with just a cr. eg. [inlinecode]awk '{ sub("\r$", ""); print }' winfile.txt > unixfile.txt[/inlinecode] you could also use a utility called [B]tofrodos[/B] which is … | |
Re: ater [code] cout<<"command?"; cin>>command;[/code] you need to remove trainling whitespaces left in the buffer. modify the line to [code]getline( cin >> ws, datafind );//now this should be ok![/code] and you should be ok. note: there are other logical errors in your code, locate them after you fix this one first. | |
Re: [url]http://developer.apple.com/tools/xcode/[/url] [url]http://mac.softpedia.com/progDownload/Apple-Xcode-Download-7935.html[/url] | |
Re: you are making this way too complicated. to check if an integer is divisible by another, use the [B]%[/B] operator instead of floating points. > ..against the current vector of primes to see if any primes divide into the number evenly. you need to check only up to the square … | |
Re: > actually did my changes by adding line[i] - 48 to it to make it back to '7'. [inlinecode]line[i] - '0'[/inlinecode] would be much better; you program would then be not dependant on a particular character encoding. | |
Re: if MyControl is a polymorphic type: [code]// .... try { MyControl& control = dynamic_cast<(MyControl&>( mControl ) ; control.DoSomething(); } catch( const std::bad_cast& ) { // TODO: cast failed; handle it } // ...[/code] if not: [code]// .... MyControl& control = static_cast<(MyControl&>( mControl ) ; // it is the programmer's (this … | |
Re: one way to implement dragon's algorithm: [code=cplusplus]#include <iostream> #include <sstream> using namespace std ; enum { delimiter = '_' } ; int digits_beyond_delimiter( const string& str ) { istringstream stm(str) ; if( stm.ignore( str.size(), '_' ) ) { int number ; if( stm >> number ) return number ; } … | |
Re: >> can a friend method of a derived class use base class's protected members friend functions have the same access rights as the members of the class. a derived class can access (only) inherited protected members of the base class. if a derived class can access the base class's protected … | |
Re: > I should define _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE to the .cpp files where I use fread and fwrite? yes, if you want to use files of sizes beyond the usual limit of 2GB on 32 bit systems. see the documentation for these macros [URL]http://www.delorie.com/gnu/docs/glibc/libc_13.html[/URL] if you are on linux, you also … | |
Re: > I was wondering why the windows compiler (specifically win32) tolerated such kind of error past tense is correct; it does not any more. microsoft c++ 6 was released prior to the the adoption of c++98; and behaved like c as far as for loops were concerned. microsoft c++ 7 … | |
Re: [code] if(truck <= v) // begin if statement { ... (dynamic_cast<Truck*>(vptr[k])) -> DOTLicense() ... } else { ... } // end if statement[/code] the dynamic_cast operator in c++ is a run-time cast operator; the corrctness of the result of the cast is guaranteed by the implementation if the cast succeeds. … | |
Re: [url]http://msdn2.microsoft.com/en-us/library/dk77e5e7(VS.80).aspx[/url] and you should be using a std::ifstream (instead of a CFile). | |
Re: once you read a line from the file, do not copy it if it starts with "telemetre_". eg. [code]const char remove_this[] = "telemetre-" ; string line ; while( getline(infile,line) ) { if( line.compare( 0, sizeof(remove_this)-1, remove_this ) != 0 ) outfile << line << '\n' ; }[/code] to compare the … | |
Re: > DLLs only export functions, not classes dlls export addresses of symbols. the symbols may be of anything which has external linkage. eg. [code] int symbol_one(double) { /* ... */ } int symbol_two = 67 ; class X { int symbol_three(double) ; static int symbol_four ; }; int X::symbol_three(double) { … | |
Re: let us get this straight. it is usually a technical error for a class/struct to contain members which represent unencapsulated resources (unless the class/struct itself is an encapsulating wrapper for a *single* raw resource). here is a simple example: [code]struct book { book( const char* t, const char* a ) … | |
Re: > How can i see the assembly produced by the compiler{if it is possible}? [B]gcc[/B]: to generate assembly pseudo code, use the -S switch. eg. [inlinecode]g++ -O2 -S -c whatever.cc[/inlinecode] to see the C code together with the assembly it was converted to: [inlinecode]g++ -c -g -O2 -Wa,-a,-ad whatever.cc > … | |
Re: [URL]http://en.wikipedia.org/wiki/Lucas-Lehmer_test_for_Mersenne_numbers[/URL] | |
Re: > but if it is not year 2000, for example 2001. than this method wouldn't work? a normal year has 365 days, a leap year has 366. if in year[B] n[/B], jan 01 is a monday, jan 01 [B]n+1[/B] would be a tuesday if [B]n[/B] is not a leap year … | |
Re: is a java programmer trying to teach c++? in c++, == always means logical equivalence. as the language is not pointer-disadvantaged, you can compare addresses (again with an ==) to check for identity. the case is different in java; you cannot comare strings for equivalence using an ==. see [URL]http://www.beginner-java-tutorial.com/java-string-comparison.html[/URL] … | |
Re: > How do you clear the console screen without any system-compatibility issues? when the language (and the language libraries) do not provide a portable way of doing something, the usual approch is to look for a library with an api, allowing the programmer to write code in a portable way. … | |
Re: if they are const integral values known at compile time, and you define them as [code]enum { const_one = 567, const_two = -34, /* ... */ };[/code] no storage would be allocated at all. if the values are not known at compile time, and you declare them as [code]extern const … | |
Re: [code=cplusplus]#include <iostream> #include <string> #include <sstream> using namespace std ; int main() { const char SEPERATOR = '-' ; string date_string ; getline( cin, date_string ) ; // dd-mm-yyyy ; istringstream stm(date_string) ; int day=0, month=0, year=0 ; char seperator1 = 0, seperator2 = 0 ; stm >> day >> … | |
Re: > calculate the modulo-10 of the value using % ... the value may be negetive; you need to adjust for that. al alternative is a. convert the number to a string b. reverse the string c. convert the string back to a number. eg.[code=c++]int reverse( int number ) { bool … |
The End.