1,247 Posted Topics
Re: this will not work at all (assuming you are using standard c++). [code]int row; cin >> row; int const ROWS = row; int const SIZE = 30; char word[ROWS][SIZE];[/code] ROWS is not a constant known at compile time. the right way to start learning c++ is by using std::vector and … | |
Re: > ... It doesn't like my temporary array c and I can't get anything to sort ... the compiler should not like it at all (it is not c++); and should give you an error. [code]int c[size]; //array c - the temporary array for sorting[/code] size is not a constant … | |
Re: > if the only datatypes in Vehicle are int cylinders and string manufacturer, do I really need to check before assigning? you really do not need to write an assignment operator at all; the compiler will synthesize a (non-trivial) assignment operator with the correct semantics. > If so, what's the … | |
Re: remove the #include of the resource script from your main.cpp [code] //main.cpp #include <windows.h> #include "resource.h" [COLOR=Red] //[/COLOR][COLOR=Red]#include "Untitled.rc"[/COLOR] // ... [/code] | |
Re: > ... but getline can't be used with integers ... it is easier to process each element in your image as a char rather than an int. eg. [code=c++]#include <iostream> #include <fstream> #include <string> #include <vector> #include <cassert> #include <iterator> using namespace std; struct replace_chars { string operator() ( const … | |
Re: define a struct to hold the data/operations for your window struct my_window_stuff { // functions // ... // data // Texture // Window // Map // whatever else }; > In main/WinMain: > 1. initialize a my_window_stuff structure. > 2. pass its address (pointer) in the LPARAM argument of CreateWindow/CreateWindowEx … | |
Re: [code]// ... TwoD m1 ( d1 , d2 ) ; // ... [COLOR=Red]cin >> m1 ( k , j ) ;[/COLOR] // ... [/code]for this to work, the class TwoD should provide an overloaded function call operator that can take k and j as args. and would return a reference … | |
Re: [code=c++]#include <iostream> #include <iomanip> #include <fstream> #include <limits> #include <cmath> using namespace std; inline bool is_equal( double x, double y ) { const double epsilon = std::numeric_limits<double>::epsilon() ; return std::fabs( x-y ) <= epsilon * std::fabs(x) ; // see Knuth's The Art of Computer Programming // Volume 2 - Seminumerical … | |
Re: boost::filesystem library provides portable facilities to query and manipulate paths, files, and directories. it supports operating systems which provide either the POSIX or Windows API and is in regular use on a number of platforms (including Microsoft Windows and Sun Solaris) using a variety of compilers. programs using the library … | |
Re: >> what function which is similar to stat that asks for a FILE* fildes rather than int fildes? the function [inlinecode][B]int fileno(FILE *stream);[/B][/inlinecode] is part of both posix and single unix specifications. [URL]http://www.opengroup.org/onlinepubs/009695399/functions/fileno.html[/URL] this would give the file descriptor using which you can call [B]fstat() [/B]which also conforms to posix. | |
Re: in c++, a. you cannot pass an array to a function, only the address of it's first element. the number of elements has to be passed seperately. b. the name of a function can not be used as a variable c. return is a statement, not a variable. you need … | |
Re: you need to read in a complete line at one time ( use [B]std::getline[/B] ) and then extract the information from it. a simple way would be to use a [B]std::istringstream [/B]the format of your text file is not well thought out. the simplest would be to leave an empty … | |
Re: > when i type in a char, they straight away have a infinite loop. I try using the cin.clear() ... the problem is that there is some char(s) left in the input buffer which gave the error earlier and will continue to give errors till you remove it (them). eg. … | |
Re: in addition, this expression [inlinecode] sum / counter [/inlinecode] will do [B]integer[/B] division; ie. if sum ==23 and counter==7, the result would be 3, not 3.28. you could either make sum a double or write [inlinecode] double(sum) / counter [/inlinecode] to get the fractional part. it is also a good … | |
Re: here is a very old game, which requires only text input or output, is simple, and is interesting to program. [URL]http://en.wikipedia.org/wiki/Nim[/URL] | |
Re: > I would just like to know how to get the ASCII code number after inputing an ASCII character. a. change the locale of std::cin from the default locale to one using an ASCII char set. b. read the char entered by the user c. convert it to an int … | |
Re: > my variable 'advance', is a ambiguous symbol and cannot be used....why? the c++ standard library defines a function [B]std::advance[/B] (header <iterator> ; the function is used to move an iterator by a certain distance). your program would be (indirectly) including this header and also has a [inlinecode]using namespace std … | |
Re: >> how I can use "[B]explicit template instantiation[/B]" in the above example. an explicit instantiation directive consists of the keyword template followed by a declaration of the version to be instantiated. for example, [code]template std::string CTClass< std::string >::add() ; [/code] is an explicit intantiation of the member function. all the … | |
Re: perhaps this would clarify (not different, but the types involved are simpler and therefore the example is easier to follow). [code=c++]void foobar( int a, int b ) {} int main() { int a = 78 ; int foo( int(a) ) ; // is this the declaration (of a function foo) … | |
Re: the code that you posted originally will not compile (line 16 has a typo). > the last set of statements {also compiles} but it prints this � character... the most likely cause is that the iterator pos == coll.end() when you dereferenced it. | |
Re: [inlinecode]switch (randNumGen2)[/inlinecode] [B][B][B][B]randNumGen2[/B][/B][/B][/B] is not an integral expression and can not be used in a switch. did you intend [inlinecode]switch[B][B]( [/B][/B]randNumGen2->Next(1,5)[B][B] )[/B][/B][/inlinecode] ? | |
Re: > ........increasing the capacity that the buffer can hold lookup std::basic_ios<>::rdbuf and std::basic_streambuf<>::pubsetbuf > .........by "removing any ties" that the ostream object has calling std::basic_ios<>::tie(0) will remove any tie. | |
Re: [code]class GBook { // ... void inputGrades( int& ,int&, int& ); // .... void displayReport( int course_number ) ; // ... }; // ... void GBook::inputGrades( int& x1, int& x2, int& x3 ) { // ... } // ... void GBook::displayReport( int course_number ) { setCourseNo( course_number ); displayMsg(); int … | |
Re: if the number of bits and padding are known at compile time: (if not, you could use boost::dynamic_bitset [url]http://www.boost.org/libs/dynamic_bitset/dynamic_bitset.html[/url] ) [code=cplusplus]#include <iostream> #include<bitset> #include <string> template< std::size_t PAD, std::size_t N > inline std::bitset< N + PAD > pad_msb( const std::bitset<N>& bs ) { return std::bitset< N + PAD >( bs.to_string() … | |
Re: [code=cplusplus]#include <iostream> using namespace std ; // is every decimal digit of number a 0 or 1 bool is_every_digit_zero_or_one( unsigned int number ) { while( number > 0U ) { if( number%10U > 1U )return false ; number /= 10U ; } return true ; } // read in an … | |
Re: a. you do not need a sentinal node (with the value "INVALID") at the beginning of the list b. if the value you are trying to insert compares less than the value in a node, you need to insert *before* not after the node c. in more than one place, … | |
Re: > Would this be a comprehensive reference, listing and describing all the standard parts of file i/o, objects etc this book explains the stl part of the standard library very well. very good for learning that part of the c++ library and would be a handy reference later. however, if … | |
Re: > Win32 api's are using wchar_t* which is hard for me since most of the standard library are using const char* or char*. > I've been having a hard time porting these win32 apis to standard library. *sigh*. most (not all) of the c++ part of the standard library has … | |
Re: [code]int ch = getchar() ; // reads a char literal '0', '1' etc. // the integer contains the code point for the literal (depends on the charset) // to convert it to an integer digit with value 0, 1 etc. if( isdigit(ch) ) { int digit = ch - '0' … | |
Re: [code]template< typename T > class A { // ... template< typename SEARCH, typename STAT > inline void search_s( SEARCH srch, STAT stat ) { // implement here (inline) // some compilers complain otherwise. // can use the argument srch and stat here // ... } // ... };[/code] | |
Re: see [url]http://msdn2.microsoft.com/en-us/library/aa366551.aspx[/url] [url]http://msdn2.microsoft.com/en-us/library/ms684954.aspx[/url] [url]http://msdn2.microsoft.com/en-us/library/ms649011.aspx[/url] [url]http://msdn2.microsoft.com/en-us/library/aa378651.aspx[/url] | |
Re: 1 + 2 + 3 + ... + (N-1) + N == N * (N+1) / 2 for M>1, M + (M+1) + ... + (N-1) + N == N * (N+1) / 2 - M * (M-1) / 2 | |
Re: #include <functional> and use gcc 4.3 with the switch -std=c++0x [code=cplusplus]#include <iostream> #include <functional> using namespace std; int main(int argc, char * argv[]) { hash<const char*> H; cout << "foo() ->" << H("foo()") << endl; } // g++43 -std=c++0x -Wall -c -g main.cc[/code] | |
Re: [code=cplusplus]#include <algorithm> #include <vector> #include <iterator> #include <boost/assign.hpp> #include <cassert> #include <iostream> using namespace std; using namespace boost::assign; int main() { vector<int> sequence ; sequence += 52, 3, 4, 2, 49 ; enum { N = 3 } ; assert( sequence.size() >= N ) ; vector<int> last_n( sequence.end() - N, … | |
Re: >> The usual problem is trying to mix say ... They don't play well together, since a simple cin will leave a newline on the input stream the solution for this is simple (assuming that you are not interested in leading whitespaces in a line): [code] char ch ; string … | |
Re: [code]// ... for( int i = 1 ; i < 10 ; ++i ) for( int j = 0 ; j < 10 ; ++j ) for( int k = 0 ; k < 10 ; ++k ) for( int m = 0 ; m < 10 ; ++m ) … | |
Re: a. if second is not an object oriented type, using value semantics would be simpler: [code=cplusplus]#include "second.h" class first { private: second mySecond; };[/code] b. if pointer semantics are required, you would have to decide: is the pointer an *owning* pointer? if is is, what would happen if an object … | |
Re: here are two examples from the c++ standard library where specialization is used: [B]a.[/B] [B]std::vector<T>[/B] is an implementation of a dynamically resizeable array; for example [B]std::vector<double>[/B] stores a sequence of [B]double[/B] elements. [B]std::vector<bool>[/B] is a specialization. [B]sizeof(T) >= sizeof(char)[/B] for any type T. to store N [B]bool[/B] elements, the space … | |
Re: very often, encapsulation/insulation and efficiency pull in opposite directions. and c++ programmers have to do a fine balancing act between the two and decide what is most appropriate in a particular case. for example, [code=cplusplus]struct book // fully insulated, least efficient { book( const atring& t, const list<string>& a, const … | |
Re: [code] // ... size_t size = 0; // Initialize the size of the array int* a = new int[size]; // Create a dynamic array *** of size 0? *** // ...[/code] | |
Re: check the function [inlinecode]LeftistHeap::initializeHeap[/inlinecode]. valgrind is reporting 80 bytes in 10 unreachable blocks of memory allocated in this function. this is a leak. the 2 reachable blocks are not memory allocated from your code (they are allocations by libc.so and will be released on program exit) and do not constitute … | |
Re: you might find the following article (about efficient memory management of typed buffers) instructive. i did, when i first read it. reading alexandrescu almost always has that effect. [URL]http://www.ddj.com/cpp/184403806[/URL] (the article is failry old; some of the issues it discusses are being addressed in c++0x.) | |
Re: description: [url]http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1745.pdf[/url] tutorial/reference (book): [url]http://safari.awprofessional.com/0321412990[/url] | |
Re: >> How are an object’s data members initialized if a class has only an implicitly defined default constructor? if every non-static member variable of a class has default initialization and no programmer defined constructor is specified, a default constructor is deemed to be declared. if the initialization of all the … | |
Re: [inlinecode]char board[Num_Pegs * 2];[/inlinecode]is not valid c++. it is not even valid c, though g++ does allow it (unless you use the switch -std=c++98). standard c++ requires that the size of an array with an automatic or static storage duration should be a constant known at compile time. in this … | |
Re: >> ... But, now I want to add many vecters like A1+A2+...+A35 ... it would be much more flexible (also readable) to use a collection of 35 elements instead of 35 named variables of the same type. eg. [inlinecode]vector< vector<long double> > vectors_1_to_N ; [/inlinecode] and then you can, [code=cplusplus]#include … | |
Re: >> ...my mind still hasn't grasped how this number system works, is there some place I can read about it... [URL]http://en.wikipedia.org/wiki/Signed_number_representations[/URL] [URL]http://en.wikipedia.org/wiki/Two%27s_complement[/URL] the c++ standard library header <limits> has a class template numeric_limits<> with specializations for each builtin numeric type. for integral types, the interesting members of std::numeric_limits<> are: [code] … | |
Re: using libcurl would be a portable way. [URL]http://curl.haxx.se/libcurl[/URL] source or binaries for a number of platforms are available [URL]http://curl.haxx.se/download.html[/URL] libcurl can be used directly from c++. curlpp gives a c++ wrapper that uses stl, is exception and type safe; so you may want to use it. [URL]http://rrette.com/textpattern/index.php?s=cURLpp[/URL] [URL]http://rrette.com/textpattern/index.php?s=file_download&id=35[/URL] you could … | |
Re: Carbide.c++ is not a compiler. it is an eclipse-based development tool supporting development for the Symbian OS (S60, Series 80 and UIQ). the compiler that is used is a symbian/nokia hack of the gcc 2.95 (there was some talk about moving to gcc 3.0, perhaps this has been done). these … | |
Re: [code=cplusplus]#include <iostream> #include <bitset> #include <vector> #include <string> //#include <random> // c++0x #include <boost/random.hpp> // c++98 + boost using namespace boost ; // c++98 + boost using namespace std ; void fill_row_with_random_bit_pattern( vector<string>& row, size_t N ) { enum { NBITS = 8 } ; row.clear() ; row.reserve(N) ; static … |
The End.