1,247 Posted Topics
Re: a. place the call to the exit handler member function in the destructor of a class. b. create an instance of the class with a static storage duration. the order of calling C atexit / C++ destructors for objects with a static storage duration is specified by secion 3.6.3/3 of … | |
Re: [code]class objects; class food; class MainControl { public: friend [COLOR="Red"]class[/COLOR] objects; friend [COLOR="Red"]class[/COLOR] food; // ... };[/code] | |
Re: > i mean that g<A, B> () is only friend of X <B>? [code]template < typename T1, typename T2 > T1* g( T2& ) ; class A ; template < typename T > class X { friend A* g [COLOR="Red"]<>[/COLOR] ( T& ) ; // ... };[/code] | |
Re: [ICODE]boost::algorithm::split[/ICODE] works like [ICODE]std::strtok[/ICODE]. delimiters that are just single characters. use [ICODE]boost::algorithm::split_regex[/ICODE] to split character sequences where delimiters are regular expressions. for example, to split a string on delimiters which are either sequences of some number of digits or [ICODE]->[/ICODE] [code=c++]#include <string> #include <iostream> #include <iterator> #include <boost/regex.hpp> #include <boost/algorithm/string/regex.hpp> … | |
Re: [CODE=c++] // ... A *b; b = new B(param1, param2); delete b; // ...[/CODE] the destructor that is called in line 4 is A::~A() you need to call B::~B() to destroy both strings solution: the destructor for the base class must be virtual. [code]class A { public: string sa; A(string … | |
Re: > Is set like to priority_queue according to algorithm?I need a heap algorithm. no. > removing the first is so easy. > removing ...is difficult. Because priority_queue hasnt a remove function. the simplest solution may be to write your own priority_queue which has an erase function. (it will not be … | |
Re: this is one (not the most efficient) way: [code=c++]#include <iostream> #include <string> #include <cstring> #include <algorithm> template< std::size_t N > inline void copy_string_to_array( char (&array) [N][N], const char* cstr ) { std::memset( array, 0, N*N ) ; std::memcpy( array, cstr, std::min( std::strlen(cstr), N*N ) ) ; } int main() { … | |
Re: > i have lots of jpeg's inside a text file full of data. I presently search for the start of every picture. > I then want to stream the data into a new file until i reach the end of every picture ... > the end of the data i … | |
Re: [code] int sum = matrix[i][3] + matrix[i][4] ; if( sum == 2 ) ++counters[1][1] ; else if( sum == 1 ) ++counters[0][1] ; else ++counters[0][0] ;[/code] | |
Re: or [url]http://curl.haxx.se/libcurl/[/url] | |
Re: non-static member functions have an implicit argument: the this pointer (a pointer to the object the function is called on). a pointer to a free function has nothing of this kind. the dereference operators on pointers to members ( .* and ->* ) are binary operators; you dereference a pointer … | |
Re: > Does the isgood() function tell which chars are valid or not? > or is there a similar function that i could use? no, the closest you have is [CODE]template<typename char_type> std::ispunct( const char_type&, const std::locale& ) ;[/CODE] but you could easily write one of your own: [code=c++]#include <string> inline … | |
Re: this will read in a name (which may contain spaces) and write it out to a file. fill in the TODO: part [code=c++]#include <iostream> #include <string> #include <fstream> int main() { std::string name ; std::getline( std::cin, name ) ; // TODO: // add code here to transform each char in … | |
Re: [ICODE]System::Type^[/ICODE] note: you do not need a method to do this; use [ICODE]System::Object::GetType()[/ICODE] instead. eg. [ICODE]System::Type^ type = obj->GetType() ;[/ICODE] | |
Re: you could just use ICMP ping on every possible ip on your lan. (the subnet mask/broadcast address will give you this info. for example, use. [ICODE]>ifconfig -L[/ICODE] [url]http://www.freebsd.org/cgi/man.cgi?query=ifconfig&sektion=8[/url] ). even if the computer blocks ping (and everything else) you still get an entry in your arp cache. you can then … | |
Re: [url]http://www.daniweb.com/tutorials/tutorial71858.html[/url] | |
Re: [ICODE]Form::ShowDialog()[/ICODE] shows the form as a [B]modal[/B] dialog box. (the code following it is not executed until after the dialog box is closed.) to show two instances of the same form: a. create two instances of the Form (you seem to already have one instance, so create one more) b. … | |
Re: to use glut wih visual studio, all you need to do is put the glut files in places where visual studio / windows loader will look for them. glut32.dll in <windows home>/system or in a directory in your PATH glut32.lib in one of the visual studio include directories glut.h in … | |
Re: [code] // ... if (length_one >= 0) { cout << "Enter the length of the side 2 in inches: "; cin >> length_two; cout << endl << endl << "Triangle: Side 1: " << length_one << " inches"; cout << endl <<"\t Side 2: " << length_two << " inches"; … | |
Re: [QUOTE][code]// ... bool Y = true; cout <<"Enter an assignment score and type 'Y' if it was late: "; cin >> score >> Y; // ...[/code] [/QUOTE] the bool literals are [ICODE]true[/ICODE] and [ICODE]false[/ICODE]. when performing formatted input or output, the character sequences that [ICODE]bool[/ICODE] values are translated from/to depends … | |
Re: > what is the problem the problem is that [ICODE]string b;[/ICODE] creates an empty string. [ICODE]b[j]=a[i];[/ICODE] is incorrect; there are no characters in b. > i want the first character on string a to be the last char on string b > up until the last on a is the … | |
Re: > i am not quite sure how i would go about reading in the traverse and delete lines. instead of trying to do everything in one place, break it up into smaller tasks (each of which is quite manageable). > I want to set the first character of each traverse … | |
Re: if you want to iterate through a sequence container erasing elements as you go along, you must use the return value of [ICODE]container::erase[/ICODE]. the return value is a vald iterator that designates the first element remaining beyond element(s) erased, or end if no such element exists. for example, the following … | |
Re: [code] // ... val = 0; for (p=0; p<3; p++) { //val += (a[i][p]*b[p][[COLOR="Red"]i[/COLOR]]); val += (a[i][p]*b[p][[COLOR="Red"]j[/COLOR]]); cout << a[i][p] << " x " << b[p][j] << " + "; } // ... [/code] | |
Re: [url]http://msdn2.microsoft.com/en-us/library/system.windows.forms.tooltip.aspx[/url] | |
Re: the input may not be a number due to several reasons: a. it may be empty b. it may have invalid characters c. it may be too long d. it may have an invalid format eg. 45.73.2 or +-42 the simplest way to validate is perhaps a. read the input … | |
Re: in c++, [COLOR="Red"]^[/COLOR] is the bitwise exclusive OR operator. to raise an integer to a power, use [ICODE]std::pow[/ICODE] ( [ICODE]#include <cmath>[/ICODE] ) eg: [ICODE]double result = std::pow( double(3), 3 ) ;[/ICODE] | |
Re: [quote=jerryseinfeld;359843]more simple is how can LFSR work :)[/quote] see: [url]http://homepage.mac.com/afj/lfsr.html[/url] | |
Re: the [ICODE]ofstream newOccupant[/ICODE] inside the local scope of the if statement is hiding the [ICODE]ofstream newOccupant[/ICODE] that you had declared earlier. [code=c++]// ... ofstream newOccupant; if(AuthorizeEntry(IDcard,lot)) { cout<<"Lot Accessed." <<endl; if(lot == 'A') ofstream newOccupant("lot_A.txt", ios::out); // this newOccupant is a different variable inside // the local scope of the … | |
Re: > Sadly I have only C++ available to me cheer up, i/o is much (much) easier in C++ than in C#. something like this should get all the data in. [code=c++]#include <fstream> #include <string> #include <sstream> #include <vector> using namespace std ; struct Weather { int years; int months; int … | |
Re: [code] std::cout << 1.0/3 << '\t' << std::fixed << std::setprecision(2) << 1.0/3 << '\t' << std::resetiosflags(std::ios::fixed) << std::setprecision(-1) << 1.0/3 << '\n' ; [/code] | |
Re: the missing argument appears to be the one to initialize the [ICODE]style[/ICODE] member. based on comments in the base class, i guess that you are expected to pass [ICODE]"vintage"[/ICODE] as the style for [ICODE]VintagePort[/ICODE]. | |
Re: this will change the third character of every line in infile.txt to 4 and put the result in outfile.txt [ICODE]sed 's/^\(..\)\(.\)/\14/' < infile.txt > outfile.txt[/ICODE] | |
Re: if you use the algorithm [ICODE]std::search[/ICODE] with a predicate, the string does not have to be transformed. will also work on const strings (with const_iterator). [code=c++]#include <iostream> #include <algorithm> #include <cctype> struct cmpnocase { bool operator() ( char a, char b ) const { return std::toupper(a) == std::toupper(b) ; } … | |
Re: you would also need to seed the linear congruential generator using [ICODE]srand[/ICODE]. a beginner's tutorial: [url]http://www.cs.auckland.ac.nz/~jli023/c/RandomNumbers.html[/url] | |
Re: > how to display a letter with '*'s? for example, say the letter C something like this, perhaps? [code=c++]#include <iostream> enum { HEIGHT = 8, WIDTH = 8 }; const char* const C_bitmap[HEIGHT] = { "********\n", "********\n", "**\n", "**\n", "**\n", "**\n", "********\n", "********" }; int main() { for( int i=0 … | |
Re: > need to know if it "acts like a record" for a single user. yes, it does. a [ICODE]struct[/ICODE] is an aggregate that collects related pieces of information together in one place. > At the end users[userdb] is like an array for 6 struct user records? [ICODE]#define userdb 5[/ICODE] [ICODE]userdb[/ICODE] … | |
Re: > but you need to go as high as the square root of n. you need to test for divisibility only by *prime* numbers up to the root of n. if you precompute and store all primes upto 100, testing if a number less than 10000 is prime would be … | |
Re: in the end, any program is just a file stored in some file system. compilers, linkers etc. are programs that take one or more files as input and give out file(s) as output. you can modify these files like you modify any other files. [code=c++]#include <iostream> #include <cstdlib> #include <string> … | |
Re: > why do you have to 'state' the <<n1+n2 if it has already been 'stated' before in that line? in your c++ program, you have to say precisely what is it that you want done.[ICODE] cout << n1 << " + " << n2 << " = "[/ICODE] 'states' that … | |
Re: hint: [code]char* punchmeinthehead( const char* first_name, const char* middle_name, const char* last_name ) { // ... // delete[] fullname ; // instead return fullname ; }[/code] | |
Re: [ICODE]WSAEventSelect[/ICODE] [url]http://msdn2.microsoft.com/en-us/library/aa922328.aspx[/url] is probably what you are looking for. googling on [ICODE]WSAEventSelect tutorial/sample[/ICODE] should fetch you quite a few hits. here are two of them [url]http://www.codersource.net/winsock_tutorial_server_event_model.html[/url] [url]http://www.codeproject.com/KB/IP/networkevents.aspx[/url] | |
Re: you are encountering the strange behaviour because of this function (ideally it should not have compiled at all): [code]bool validity_check(int level,int n, int current[]) { for(int i=0;i<level;i++) { if(current[i]==n) return false; } //Level 0 has always full validity. if((level>0)&&(level<order-1)) { if((current[level-1]==n)|(current[level+1]==n)) return false; } if(level==order-1) { if(current[level-1]==n) return false; } … | |
Re: were you looking for a standard library function? like [B]std::accumulate[/B] ( in header [B]<numeric>[/B] ) [CODE]// vec is a std::vector<int> and N <= vec.size() int sum = std::accumulate( vec.begin(), vec.begin()+N, 0 ) ; // average == sum / double(N)[/CODE] | |
Re: not [ICODE]> g++ functions.o * .cpp[/ICODE] but [ICODE]> g++ functions.o *.cpp[/ICODE] (no space after *) better: [ICODE]> g++ -std=c++98 -Wall functions.o *.cpp[/ICODE] | |
Re: yup, the specific problem is here: [code]while((loc = [COLOR="Red"]/*vProperNouns[i]*/[/COLOR]str.rfind(vPreceeding[j], pos)) != string::npos)[/code] the more fundamental problem is the complexity of the code you have written. a while within a for within a while within a for!. why don't you simplify it by writing a function [code]bool does_precede( const string& str, … | |
Re: define a string literal [CODE]const char* const a_to_z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;[/CODE] generate a random integer [iCODE]ri[/iCODE] in the range 0 to 25 (inclusive). use [iCODE]a_to_z[ri][/iCODE] as the random letter. note: *do not* do this: [icode]char( 'A' + ri )[/icode] | |
Re: [CODE][B]std::complex<float> Z[N][P][M] ;[/B] [B]Z[/B] is an array of [B]N[/B] elements, each element of which is an array of [B]P[/B] elements, each element of which is an array of [B]M[/B] elements, each element of which is a [B]std::complex<float>[/B][/CODE] [B]std::complex<float> (*W)[M] = &Z[k][0] ;[/B] [B]W[/B] is a pointer to an array of … | |
Re: This problem is covered in detaill in Jon Bentley's Programming Pearls (Second Edition) ISBN 81-7808-022-2 (Pearson Education) see column 8 : Algorithm Design Techniques (pages 77-86) Even if you have been programming for a number of years, but have not seen this book so far, do yourself a favour. Get … | |
Re: > My sources (MSDN) for map::erase(iterator) says that erase(iterator) returns an iterator ... this is the interface given by dinkumware (and microsoft) for map<>::erase. [code]iterator erase(iterator where); iterator erase(iterator first, iterator last); size_type erase(const Key& keyval);[/code] and this is the interface as per gcc (libstdc++) [code]void erase(iterator where); void erase(iterator … |
The End.