1,247 Posted Topics

Member Avatar for helixkod

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 …

Member Avatar for vijayan121
0
197
Member Avatar for mqueene7

> ... 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 …

Member Avatar for Duoas
0
121
Member Avatar for Duki

> 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 …

Member Avatar for vijayan121
0
88
Member Avatar for twooften

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]

Member Avatar for twooften
0
1K
Member Avatar for DemonSpeeding

> ... 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 …

Member Avatar for DemonSpeeding
0
202
Member Avatar for Fromethius

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 …

Member Avatar for robgxxx
0
102
Member Avatar for Duki

[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 …

Member Avatar for ndeniche
0
87
Member Avatar for Underdog67

[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 …

Member Avatar for vijayan121
0
79
Member Avatar for amt_muk

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 …

Member Avatar for vijayan121
0
2K
Member Avatar for jaepi

>> 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.

Member Avatar for jaepi
0
1K
Member Avatar for Linda1

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 …

Member Avatar for Linda1
0
80
Member Avatar for Ratte

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 …

Member Avatar for vijayan121
0
130
Member Avatar for wjyeo

> 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. …

Member Avatar for wjyeo
0
247
Member Avatar for Koldsoul

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 …

Member Avatar for Koldsoul
0
269
Member Avatar for sneha_venky

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]

Member Avatar for vijayan121
0
218
Member Avatar for mstrmnd2008

> 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 …

Member Avatar for Narue
0
143
Member Avatar for patrickyeow

> 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 …

Member Avatar for vijayan121
0
250
Member Avatar for amt_muk

>> 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 …

Member Avatar for amt_muk
0
182
Member Avatar for n.aggel

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) …

Member Avatar for n.aggel
0
114
Member Avatar for n.aggel

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.

Member Avatar for n.aggel
0
402
Member Avatar for lotsofsloths

[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] ?

Member Avatar for lotsofsloths
0
178
Member Avatar for tnvkrishna

> ........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.

Member Avatar for vijayan121
0
115
Member Avatar for step2stepgirl

[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 …

Member Avatar for step2stepgirl
0
217
Member Avatar for gaasha

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() …

Member Avatar for vijayan121
0
131
Member Avatar for jrice528

[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 …

Member Avatar for WaltP
0
122
Member Avatar for Schmitty27

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, …

Member Avatar for vijayan121
0
106
Member Avatar for ubercat

> 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 …

Member Avatar for kako13
0
112
Member Avatar for jaepi

> 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 …

Member Avatar for jaepi
0
985
Member Avatar for jimwalther

[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' …

Member Avatar for jimwalther
0
164
Member Avatar for hectic

[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]

Member Avatar for vijayan121
0
510
Member Avatar for shizu

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]

Member Avatar for shizu
0
165
Member Avatar for makmak02

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

Member Avatar for makmak02
0
90
Member Avatar for asilter

#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]

Member Avatar for vijayan121
0
360
Member Avatar for Crouchinho

[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, …

Member Avatar for vijayan121
0
175
Member Avatar for hectic

>> 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 …

Member Avatar for vijayan121
0
294
Member Avatar for zandiago

[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 ) …

Member Avatar for zandiago
0
245
Member Avatar for JoBe

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 …

Member Avatar for JoBe
0
122
Member Avatar for n.aggel

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 …

Member Avatar for vijayan121
0
127
Member Avatar for jack223

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 …

Member Avatar for vijayan121
0
192
Member Avatar for Dee76

[code] // ... size_t size = 0; // Initialize the size of the array int* a = new int[size]; // Create a dynamic array *** of size 0? *** // ...[/code]

Member Avatar for Dee76
0
155
Member Avatar for n.aggel

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 …

Member Avatar for n.aggel
0
416
Member Avatar for Brent.tc

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.)

Member Avatar for Narue
0
162
Member Avatar for Laiq Ahmed

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]

Member Avatar for vijayan121
0
107
Member Avatar for conan19870619

>> 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 …

Member Avatar for n.aggel
0
575
Member Avatar for spankyg

[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 …

Member Avatar for spankyg
0
138
Member Avatar for random7

>> ... 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 …

Member Avatar for vijayan121
0
133
Member Avatar for AllenN

>> ...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] …

Member Avatar for AllenN
0
208
Member Avatar for yassar

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 …

Member Avatar for vijayan121
0
214
Member Avatar for pmahalakshmi

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 …

Member Avatar for vijayan121
0
97
Member Avatar for SurviBee

[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 …

Member Avatar for SurviBee
0
88

The End.