1,247 Posted Topics
Re: the problem is discussed in this thread: [url]http://www.daniweb.com/forums/thread115838.html[/url] | |
Re: [code]//... case 2: cout << "what is the title of the game you would like to remove?\n"; cin >> game; myIterator = find( games.begin(), games.end(), game ) ; if ( [COLOR="Red"]myIterator != games.end()[/COLOR] ) { games.erase(myIterator); } break; // ...[/code] | |
Re: [LIST=1] [*]you could have name as a non-static member in the class. this can be used to give a name to each object. [*]you could use an enum or a variable to give a name (identifier) for a position in the array. [*]you could create an alias (reference) with a … | |
Re: [code]for( int i=0 ; i<10 ; ++i ) numb2[i] = i%2 == 0 ? (i/2)*5 : i ;[/code] | |
Re: >> I'm guessing using whitespace and periods as delimiters as the parameters, >> but how do I use both delimiters at the same time. as dragon has shown, using whitespaces alone as delimiters is very easy; this is the default in c++. to also use period, ; , :, ? … | |
Re: > how to link classes with each other? classes are types. are you looking for how to implement a typelist? a tutorial introduction to typelists: [url]http://www.ddj.com/cpp/184403813?_requestid=1305388[/url] you might then want to read Alexandrescu's Modern C++ Design (Addison-Wesley Longman, 2001). and look up Boost.MPL [url]http://www.boost.org/doc/libs/1_35_0/libs/mpl/doc/index.html[/url] which has a ready made framework … | |
Re: > So I want to know is it possible to compile a code in such a way that if it is compiled > on RHEL 5 machine, same compiled code should work on any other Linux distros? the problem is caused by changes in the ELF binary format between RHEL4/FC5 … | |
Re: [code]for(it = aMap.begin(); it != aMap.end(); it++){ //some processing if(//some condition){ //some processing aMap.erase(key); [COLOR="Red"]// this is undefined behaviour // the iterator is invalid after the erase[/COLOR] it--; } }[/code] this will work on conforming implementations: [code]it = aMap.begin() ; while( it != aMap.end() ) { //some processing if(some_condition) { … | |
Re: using c++09 variadic templates [url]http://www.osl.iu.edu/~dgregor/cpp/variadic-templates.pdf[/url] [code=c++09]#include <iostream> template < typename T > T largest( T first, T second ) { return first > second ? first : second ; } template < typename T, typename... U > T largest( T first, U... rest ) { return largest( first, largest( rest... … | |
Re: to make one line of your ladder: [code=c++]#include <string> std::string make_line( char X, std::size_t num_chars, std::size_t num_spaces_on_left ) { const char space = ' ' ; return std::string( num_spaces_on_left, space ) + std::string( num_chars, X ) ; }[/code] | |
Re: > i try to avoid copying anything than 2 pointers... swapping pointers is easy; swap pointers to arrays just like you swap any other pointers. [code=c99]#include <stdio.h> void swap( int rows, int cols, float (**after)[rows][cols] , float (**before)[rows][cols] ) { float (*temp)[rows][cols] = *after ; *after = *before ; *before … | |
Re: this is what the C++ standard specifies about the layout (note that there are no separate specifications for struct and class) [QUOTE]Nonstatic data members of a (non-union) class declared without an intervening access-specifier are allocated so that later members have higher addresses within a class object. The order of allocation … | |
Re: > Shouldn't "this" inside CMeasurement::getSumMethodName have the same value as &meas? not necessarily. if getSumMethodName is a function inherited from a base class (in a multiple inheritance scenario) and the base class is at a non-zero offset, the this pointer in the function should point to the base class sub-object … | |
Re: > is it possible to declare a windows CRITICAL_SECTION object as a member of a base class > that will not be created for each derived class? yes > Does this look like a reasonable way to implement CRITICAL_SECTION yes, this is the normal way when you want to synchronize … | |
Re: [code=c++]#include <string> #include <vector> #include <fstream> typedef unsigned char byte ; void bwt_encode( byte* buf_in, byte* buf_out, int size, int* primary_index ) ; void bwt_decode( byte* buf_in, byte* buf_out, int size, int primary_index ) ; int main() { std::ifstream fin("Dec of Ind.txt") ; std::string word ; while( std::getline(fin,word) ) { … | |
Re: > is there any way to use threads in c++ the ISO standards committee (c++09) has voted voted in a number of concurrency extensions into the working draft (memory model, atomics library, basic threads, locks, and condition variables). an asynchronous future<T> type would be added later, but features like thread … | |
Re: > Is there any standard function to test the endianess of the system? [code=c++]inline bool little_endian() { union { long i ; char c[ sizeof(long) ] ; }; i = 1 ; return c[0] == 1 ; }[/code] | |
Re: have a look at the source code for Boost.multi_array [url]http://www.boost.org/doc/libs/1_35_0/libs/multi_array/doc/index.html[/url] [url]http://www.boost.org/doc/libs/1_35_0/libs/multi_array/doc/user.html#sec_access[/url] | |
Re: > Should i just take Dijkstra or Kruskal that i have already coded and add the vertice weights into the game ? that would not work. Kruskal does something like this create a set containing all the edges in the graph ... remove an edge with minimum weight from the … | |
Re: [url]http://www.cppreference.com/cppsstream/str.html[/url] | |
Re: with [code]class Rectangle { //... public: //... Rectangle operator +(Rectangle); //... };[/code] // a, b, c are Rectangles [ICODE]a = b + c ;[/ICODE] evaluates to [ICODE]a = b.operator+(c) ;[/ICODE] since [ICODE]c[/ICODE] is passed by value, a copy of [ICODE]c[/ICODE] is made (and destroyed later). the return value is an … | |
Re: [url]http://www.comp.dit.ie/rlawlor/Alg_DS/searching/3.%20%20Binary%20Search%20Tree%20-%20Height.pdf[/url] | |
Re: c++98 has the convenient [ICODE]std::pair<>[/ICODE]. c++09 also has [ICODE]std::tuple<>[/ICODE]. [code=c++]#include <utility> #include <algorithm> #include <tuple> std::pair<int,int> min_n_max( const int* arr, std::size_t N ) { // invariant: N > 0 int low = arr[0] ; int high = arr[0] ; for( std::size_t i=1 ; i<N ; ++i ) { low = … | |
Re: sort before inserting the string into the multimap? [code]void fill_mmap( std::multimap< std::string, int >& mmap, std::ifstream& file ) { std::string line ; for( int line_num = 1 ; std::getline( file, line ) ; ++line_num ) { std::sort( line.begin(), line.end() ) ; mmap.insert( std::make_pair( line, line_num ) ) ; } }[/code] | |
Re: > Is there anything that 'wraps' pipes? i do not know of any, but it is very easy to roll out one of our own. eg. [code=c++]#include <stdio.h> #include <boost/iostreams/device/file_descriptor.hpp> #include <boost/iostreams/stream.hpp> #include <fstream> #include <iostream> using namespace boost::iostreams ; struct opipestream : stream< file_descriptor_sink > { typedef stream< file_descriptor_sink … | |
Re: [code]void clearCharArray( char arrayToClear[] ) { int arrayLength = 0; // Get the length of the array passed [COLOR="Red"]// this will not give you the length of the array passed [/COLOR] arrayLength = sizeof( arrayToClear ); [COLOR="Red"]// equivalent to arrayLength = sizeof( char* ) ;[/COLOR] for( int i = 0; … | |
Re: > Are you talking about a class that only has static members and doesn't have a public constructor? >> yes that is the java style of programming. in C++, using a namespace for this purpose is canonical. [code]class foo { foo() ; public: static int f() ; static double value … | |
Re: one way to extract the digits from a number is to convert the number to a string and then convert the characters in the string to digits. [code=c++]#include <sstream> #include <vector> #include <functional> template< typename NUMERIC_TYPE > std::vector<int> get_digits( const NUMERIC_TYPE& number ) { // invariant: number is non-negetive std::ostringstream … | |
Re: another way is to use a "tag sort". ie. create an index into the vectors and then sort the indices, rather than the three vectors. note: this is usually done for efficiency reasons (swap a pair of integers instead of swap three pairs of strings). [code] // ... std::vector<std::string> lastnames; … | |
Re: [code=c++]#include <vector> template< typename T > void magnify( std::vector< std::vector<T> >& vec, size_t BY = 2 ) { std::vector< std::vector<T> > temp(vec) ; vec.clear() ; for( size_t i=0 ; i<temp.size() ; ++i ) { std::vector<T> row ; for( size_t j=0 ; j<temp[i].size() ; ++j ) row.resize( row.size()+BY, temp[i][j] ) ; … | |
Re: [url]http://www.nongnu.org/dmidecode/[/url] [url]http://ezix.org/project/wiki/HardwareLiSter[/url] | |
Re: > the way i'm trying to do is using a while loop and checking if words are more than 3 letters > long....if they are i apply changes.... > if i come accross nodes other than "alphabetical" (like a "space")within 3 nodes back the loop > breaks..do nothing..change nothing... the … | |
Re: verify that the element is present first: [code]void student::drop_course(int d) { vector<int>::iterator f = find(c_id.begin(), c_id.end(), d); [COLOR="Red"]if( f != c_id.end() )[/COLOR] { c_id.erase(f); cout << "You have deleted course number " << d << endl; } }[/code] if there are duplicate values in the vector, you need to put … | |
Re: let's say you have a struct/class of this kind: [code=c++]struct A { int number ; double value ; char name[30] ; };[/code] and you want to sort an array of [ICODE]A[/ICODE]s on the member [ICODE]value[/ICODE]. first, write a comparison function that the sort can use which accepts two [ICODE]A[/ICODE]s to … | |
Re: the C library [ICODE]clock()[/ICODE] does not give the wall clock: [QUOTE]the clock() function determines the amount of processor time used since the invocation of the calling process, measured in CLOCKS_PER_SECs of a second. [/QUOTE] just sleeping or waiting for input will work for [ICODE]time()[/ICODE] (which gives the wall time), not … | |
Re: > a completely literal translation into C++ would be like this yes, but we can do much better in C++. be type-safe and const-correct. [code=c++]template< typename T > class Node { private: T item; Node<T>* next; public: Node( const T& obj ) : item(obj), next(0) {} T& getItem() { return … | |
Re: as your 2D vector is 'rectangular' ( not 'jagged' ), you could just [code=c++]#include <vector> int main() { // 25,000 '42's in a square matrix enum { N = 5000, M = 5000, VALUE = 42 }; using std::vector ; vector< vector<int> > Numbers( N, vector<int>( M, VALUE ) ); … | |
Re: download [url]http://www.openssl.org/source/openssl-0.9.8g.tar.gz[/url] unzip the tarball, read INSTALL.W32 build the library using vc++ [url]http://www.openssl.org/support/faq.html#BUILD7[/url] [url]http://www.openssl.org/support/faq.html#PROG2[/url] | |
Re: ideally, do not use the (now deprecated) functionality in namespace [ICODE]__gnu_cxx[/ICODE]. they have been superceded by tr1 in c++0x. use [ICODE]-std=c++0x[/ICODE] (gcc 4.3) , [ICODE]std::tr1[/ICODE] (gcc4.2) or [ICODE]boost::tr1[/ICODE] (earlier versions). the error is because [ICODE]__gnu_cxx::hash<>[/ICODE] is a struct (function object); not a function. if you have to use it, use … | |
Re: in the original code, the layout of classes a and b are as follows (addresses increasing from the bottom of the page to the top): [code] layout of object of class A _____________________ | | | | | int a1 | | | A* -------->--------------------- layout of object of class … | |
Re: > I'm looking for simplicity more than anything else. I want to be able to store scripts in our > database, call them from within our C++ game engine, be able to pass arguments to them > and be able to receive data back from them. I'd also like them … | |
Re: do not pass the address of a local variable (with automatic storage duration) to a thread function; it may not be around by the time the thread executes. [code=c++]// ... char* input_sentence = new char[32]; std::strcpy( input_sentence, "ANGLE 360" ) ; thread = _beginthread( SerialThread, 8192, input_sentence ) ; // … | |
Re: > How do I match the user-entered input to item #2 in the text file the closest matching string in the text file is the one with the smallest Levenshtein distance (edit distance) from the user-entered input. [url]http://en.wikipedia.org/wiki/Levenshtein_distance[/url] > and also detect that the difference between the user-entered input and … | |
Re: inlining does not take place in the presence (or absence) of some compiler switches / #pragma directives. eg. presence of [ICODE]-fno-inline[/ICODE] or [ICODE]-finline-limit=small_number[/ICODE] / absence of [ICODE]-O[/ICODE] in g++ for functions that are called using pointers obtained at runtime. eg. C callbacks (the comparison function for qsort), C++ virtual functions … | |
Re: > a different program to read from that file BEFORE the first program is finished writing to it. the output to a file is buffered at many levels: by the fstreambuf of the c++ library and by the operating system (cache manager). to achieve coherence between the two processes' view … | |
[url]http://www.informit.com/articles/article.aspx?p=1192024[/url] | |
Re: > I would like to be able to read from pipe in child so I know what parent has sent. > How to do this ... the simplest way would be to use [ICODE]read[/ICODE] and [ICODE]write[/ICODE] on the anonymous pipe. man read(2) [url]http://www.freebsd.org/cgi/man.cgi?query=read&apropos=0&sektion=2&manpath=FreeBSD+7.0-stable&format=html[/url] man write(2) [url]http://www.freebsd.org/cgi/man.cgi?query=write&apropos=0&sektion=2&manpath=FreeBSD+7.0-stable&format=html[/url] [code=c]#include <stdio.h> #include <unistd.h> … | |
Re: use the Boost.Python library to load the python interpretor into C++ and use Boost.Python's [ICODE]eval[/ICODE] or [ICODE]exec[/ICODE] to call the python code from within C++. [url]http://www.boost.org/doc/libs/1_35_0/libs/python/doc/tutorial/doc/html/python/embedding.html#python.using_the_interpreter[/url] | |
Re: put all the common stuff in a base class and inherit from it. [code=c++]#include <iostream> template< typename E > struct enemy_manager_base { void same_for_all() { std::cout << "same for all enemies\n" ; } }; template< typename E > struct enemy_manager : enemy_manager_base<E> { void to_be_specialized() { std::cout << "generalization of … |
The End.