1,247 Posted Topics

Member Avatar for jaepi

use an array. eg. [code=cplusplus] enum { MAX_STUDENTS = 16 }; Student students[MAX_STUDENTS] ; for( int i=0 ; i<MAX_STUDENTS ; ++i ) { // ... cin >> students[i].first_name ; // etc. } [/code] you should also modify function print_student to take const string& args (not void*). passing by reference is …

Member Avatar for jaepi
0
121
Member Avatar for jaepi

[code=cplusplus] ps->first_name == (*ps).firstname ; // ok MyClass& ref = *ps ; ref.first_name ; // ok *(ps).first_name ; // error, equivalent to *(ps.first_name) ; // error, ps is a pointer // reason: operator precedence [/code]

Member Avatar for jaepi
0
213
Member Avatar for olams

the stanard libary <stack> and <queue> are just container adapters, eg. [code=cplusplus] template< typename T, typename CNTR = std::deque<T> > struct queue ; [/code] they just adapt an implementation of a sequence container to provide the interface required for a stack/queue. [quote=Narue;372810]...You can also use a vector or deque as …

Member Avatar for olams
0
187
Member Avatar for desijays

[code] // ... base( int t ) : i(t) {} // initialize member i with t // ... [/code]

Member Avatar for vijayan121
0
183
Member Avatar for Matt Tacular

[code=cplusplus] int howManyCatsFunction() { cout << "there " << (Cat::HowManyCats == 1 ? "is " : "are " ) << Cat::HowManyCats << " cats alive!" << endl; } [/code] you also need to write a copy constructor which increments Cat::HowManyCats to get the right number always.

Member Avatar for Matt Tacular
0
242
Member Avatar for addicted

MIT's Technology Review magazine published an interview with Stroustrup in Nov, 2006: [B]'The Problem With Programming: Bjarne Stroustrup, the inventor of the C++ programming language, defends his legacy and examines what's wrong with most software code.' [/B] link: [URL]http://www.technologyreview.com/Infotech/17831/[/URL] this generated such heated debate for an example, see: [URL="http://it.slashdot.org/article.pl?sid=06/12/05/0045234%29"]http://it.slashdot.org/article.pl?sid=06/12/05/0045234 [/URL] …

Member Avatar for adotl
0
113
Member Avatar for laconstantine

[quote=laconstantine;371241]...c++ takes function name as an address of it...[/quote] c++ takes the name of the function (as an expression) to be either a reference to the function or a pointer to the function. eg. [code=cplusplus] #include <iostream> void foo( void(*pfn)() ) { std::cout << "pointer\n" ; } void foo( void(&rfn)() …

Member Avatar for laconstantine
0
149
Member Avatar for radskate360

you are probably trying to enter a name that has embedded (white) spaces. to read an entire line (may contain white spaces) use getline. getline( cin, employee ) ;

Member Avatar for Narue
-1
671
Member Avatar for minigweek
Member Avatar for Covinus

you need to use a CPaintDC (not a CClientDC) in a handler for OnPaint (WM_PAINT requires calls to BeginPaint/EndPaint). it would be much better (and easier) if you override the virtual function CView::OnDraw( CDC* ) and write your code for painting the view there (and not implement OnPaint yourself). let …

Member Avatar for Covinus
0
111
Member Avatar for Masood Ali

if you are using the current version of platform sdk: header is [B]winsock2.h[/B] import library (link to) [B]ws2_32.lib[/B] shared library (dll) [B]ws2_32.dll[/B]

Member Avatar for vijayan121
0
301
Member Avatar for lotsofsloths

[code=cplusplus] private: System::Void button1_Click( System::Object^ sender, System::EventArgs^ e) { textBox1->Text = __box( randNumGen->Next(0,41) )->ToString(); } [/code]

Member Avatar for lotsofsloths
0
153
Member Avatar for sInFuL69er

this would probably be more readable. and as efficient with a decent compiler. [code=cplusplus] struct client { explicit inline client( int a, int b, const std::string& n ) : aa(a), bb(b), name(n) {} int aa; int bb; std::string name ; }; extern std::vector<client> vec ; extern std::istream file ; int …

Member Avatar for vijayan121
0
107
Member Avatar for afflictedd2

[quote=afflictedd2;369935]The reason I have to give this a fixed size, is becuase I have to map this in shared memory...[/quote] just placing the map in shared memory is insufficient; you would need to a. write a custom allocator (compatible with std::allocator) that can (sub)allocate from the shared memory region for …

Member Avatar for vijayan121
0
119
Member Avatar for laconstantine

at the place where the definition of the array is visible, sizeof will give the size of the entire array. it is when you use the name of the array in an expression that it is treated as a pointer to the first element. [code=cplusplus] #include <iostream> int main() { …

Member Avatar for newprog
0
237
Member Avatar for kylcrow

convert a string to int this way. [code=cplusplus] string test = "1234" ; istringstream stm(test); int num = 0; stm >> num ; // if using boost (boost lexical cast), it is easier num = boost::lexical_cast<int>(test) ; [/code]

Member Avatar for vijayan121
0
143
Member Avatar for satyanarayanam

[quote=Narue;364327]>This will work in C++ wht abt c? No, it won't work in either because you can't call a function at global scope....[/quote] calling a function at global scope is certainly possible in C++. dynamic initialization of statics at global scope is supported; here caling printf to initialize a global …

Member Avatar for vijayan121
0
134
Member Avatar for kylcrow

[code=cplusplus] #include <iostream> #include <string> #include <cassert> int main() { std::string city = "Memphis" ; std::string state = "Tennessee" ; assert( city.size() < 16U ) ; std::string result = city ; result.insert( result.end(), 16U-result.size(), ' ' ) ; result += state ; std::cout << result << '\n' ; // or …

Member Avatar for kylcrow
0
134
Member Avatar for Zay

[quote=Zay;359173][COLOR=red][COLOR=dimgray]for checking if word is Palindrome-[COLOR=teal]madam[/COLOR]-. or not by push half of the word in a stack and then compare it with the other half of the word)[/COLOR][/COLOR][/quote] why do you need a stack at all? [code=cplusplus] template< typename CHAR_TYPE> inline bool is_palindrome( const CHAR_TYPE* begin ) { const CHAR_TYPE* …

Member Avatar for Zay
0
137
Member Avatar for laconstantine

as a matter of principle, do not write [code] char *ptr = "String Literal"; [/code] even if your compiler does not complain about it. instead always write [code]const char* ptr = "String Literal"; const char* const ptr2 = "another literal" ; // more usual [/code] programming is much simpler if …

Member Avatar for Narue
0
302
Member Avatar for mariocatch

get to the command line terminal, cd to the directory and type [B]copy /A *.txt all.txt [/B]you will get one big text file. i'm not sure about microsoft (or any other) word, but it should be possible to convert a text file to a word processing document.

Member Avatar for vijayan121
0
317
Member Avatar for fatboysudsy

looks like a buffer overflow in the line [code] fscanf(fp, "%s %s %s %s",part1,part2,part3,part4); [/code] the contents of the file is something that is not under programmatic control; a secure alternative should be used.

Member Avatar for vijayan121
0
106
Member Avatar for Lutzee
Member Avatar for Ancient Dragon
0
49
Member Avatar for yesm

[code=cplusplus] struct eq_course_number { explicit eq_course_number( int n ) : course_num(n) {} bool operator() ( const course& c ) const { return c.get_number() == course_num ; } int course_num ; }; // cin >> target; if( remove_if ( cache.begin(), cache.end(), eq_course_number(target) ) != cache.end() ) cache.pop_back() ; [/code] an alternative …

Member Avatar for vijayan121
0
582
Member Avatar for slanker70

[quote=iamthwee;358319]An array of objects should be handled in a similar fashion to an array of ints or strings for that matter.[/quote] this is possible only if there is an accessible default constructor.

Member Avatar for vijayan121
0
158
Member Avatar for sushanttambare

[quote=Rashakil Fol;356500]Maybe [code]int i = p * q << 12; int j = (i >> (sizeof(int)-1) * CHAR_BIT) & (~0xF) i = (i & j) | (~ j);[/code][/quote] this would be about twice as slow as the original code. and the code size would also be close to double the …

Member Avatar for Infarction
0
118
Member Avatar for kmachstang

unless the size is known at compile time, or there is an externally imposed constraint, it would be easier and less error prone to use a std::vector rather than a c-style array. [code=cplusplus] #include <iostream> #include <fstream> #include <sstream> #include <string> #include <vector> #include <cassert> #include <algorithm> #include <iterator> using …

Member Avatar for vijayan121
0
249
Member Avatar for spankyg

it does print CleanUP; try it from the command line in a terminal. instead of (double) clicking the executable.

Member Avatar for mariocatch
0
345
Member Avatar for slanker70

[code=cplusplus] #include <iostream> #include <string> using namespace std ; struct account { explicit account( const string& name, double amount = 0.0 ) : _name(name), _amount(amount) {} // ... private: const string _name ; double _amount ; }; int main() { string name ; double amt ; cout << "enter name …

Member Avatar for vijayan121
0
279
Member Avatar for jenymaru08

[quote=jenymaru08;356472] can i ask what is the purpose or use of iomanip in C++ ?[/quote] to produce formatted output, or to perform operations like flushing the stream, the stream classes privide member functions. eg. [code=cplusplus] std::cout.width(10) ; std::cout.fill('0') ; std::cout.setf( ios_base::fixed, ios_base::floatfield ) ; std::cout.precision(2) ; std::cout << 100.2 << …

Member Avatar for vijayan121
0
128
Member Avatar for squinx22

a. [URL]http://www.boost.org/libs/serialization/doc/index.html[/URL] b. [URL="http://www.gnu.org/software/commoncpp/"][U][COLOR=#0000ff]http://www.gnu.org/software/commoncpp/[/COLOR][/U][/URL] c. [URL="http://www.sourceforge.net/projects/eternity-it/"][U][COLOR=#0000ff]www.sourceforge.net/projects/eternity-it/[/COLOR][/U][/URL] d. [URL="http://www.s11n.net"][U][COLOR=#0000ff]www.s11n.net[/COLOR][/U][/URL] e. [URL]http://msdn2.microsoft.com/en-us/library/caz3zy5s(VS.80).aspx[/URL]

Member Avatar for vijayan121
0
90
Member Avatar for vijayan121

variations of this are being posted repeatedly here. hope this will clarify things once and for all. [code=c] // to choose a random element from a sequence when // a. you do not know how many elements are there before hand // b. you want to make one single pass …

Member Avatar for vijayan121
0
242
Member Avatar for MaestroS

if you are comfortable with c++ (ie. you can do more than write c code using c++ syntax), you would find the spirit recursive descent parser framework (part of the boost libraries) easy to use. internally, it uses template meta-programming techniques; but to use it productively, you just need to …

Member Avatar for MaestroS
0
1K
Member Avatar for Thinka

[quote=Thinka;354794]Actually, my idea is to run rand (not sure how many times I'll need to), and to then say for each time it returns a number, the program should check that current number with the previous one; if the current number is larger than the previous one, it gets printed …

Member Avatar for Thinka
0
290
Member Avatar for jrivera

you are getting the error here. [code]my_reverse_iterator p(it);[/code] this is because my_reverse_iterator is a template class; you are not using it as such. change that to [code] my_reverse_iterator<vector<int>::iterator> p(it); [/code] and you can get started on the rest of the class. i presume you are not allowed to use the …

Member Avatar for vijayan121
0
1K
Member Avatar for scarface3288

the easiest way that i know is to use the boost tokenizer library. [code=cplusplus] #include<iostream> #include<boost/tokenizer.hpp> #include<string> #include <fstream> int main() { using namespace std; using namespace boost; ifstream file( __FILE__ ) ; string str ; while( getline( file, str ) ) { tokenizer<> toker( str ) ; for( tokenizer<>::iterator …

Member Avatar for iamthwee
0
4K
Member Avatar for JINX_

the function(s) [B]next_permutation[/B] in <algorithm> would generate the next permutation. you could call that repeatedly.

Member Avatar for JINX_
0
132
Member Avatar for MukeshZ

the ordering of data declared as bit fields is implementation dependant. you have to test and figure out what it is for your compiler. [code=cplusplus] #include <iostream> int main() { // assumes that the ordering of data declared as bit fields is from // low to high bit. this is …

Member Avatar for vijayan121
0
142
Member Avatar for amt_muk

[quote=joeprogrammer;353091]in fact the performance loss is so minimal, it's hardly worth taking that into account when trying to decide when and where to use exception handling.[/quote] not true. exceptions are designed with the idea that a. you do not have to pay a high performance penalty in the event of …

Member Avatar for vijayan121
0
128
Member Avatar for MukeshZ

construct a bitset using the string and then convert it to a ulong. [code=cplusplus] #include <iostream> #include <string> #include <bitset> #include <limits> using namespace std ; int main() { string str = "00000100" ; cout << bitset<numeric_limits<unsigned long>::digits>(str).to_ulong() << '\n' ; } [/code]

Member Avatar for vijayan121
0
161
Member Avatar for srinath.sec

[code] enum { N=20, M=50 }; int(*a)[M] = malloc( sizeof( int[M] ) * N ) ; // C int(*b)[M] = new int[N][M] ; // C++ [/code]

Member Avatar for John A
0
88
Member Avatar for wujianwei

this kind of functionality is required only when the generic or metaprogramming paradigms are used. otherwise, when you write a function in a statically typed language, you already know the type of every expression. for a tutorial on discovering and using information about types, see this: [url]http://www.boost.org/doc/html/boost_typetraits/background.html[/url] these books would …

Member Avatar for vijayan121
0
115
Member Avatar for jrivera

[quote=jrivera;350578] what is the definition of the + operator for STL vectors? template<typename T, typename Allocator> vector<T, Allocator> &operator+ (const vector<T, Allocator> &a, const vector<T, Allocator> &b) and do I just code this outside of main?[/quote] yes, you define it as a global. however, there is a logical error in …

Member Avatar for vijayan121
0
85
Member Avatar for jrivera

[code=cplusplus] #include <iostream> #include <vector> #include <map> #include <string> #include <algorithm> using namespace std; typedef map<string,int> simap ; typedef simap::iterator miterator ; typedef vector<miterator> ivector ; ivector find_values( simap& m, int val ) ; int main() { simap map ; map["one"] = 1; map["two"] = 2; map["three"] = 3; map["four"] …

Member Avatar for vijayan121
0
132
Member Avatar for Slavrix

what you need is integer division. in your program, temp is a float. float(123)/100 will give you 1.23, not 1. and a standards-compliant compiler would give you a compile-time error if you try float(123)%100

Member Avatar for WaltP
0
113
Member Avatar for Slavrix
Member Avatar for Slavrix
0
588
Member Avatar for Mac.Z

[quote=Mac.Z;348625]let's say the user enters a value in this format xx:xx:xx, where xx is an integer, how can I assign each xx to integer vars? [/quote] this is one way. [code] #include <string> #include <iostream> #include <algorithm> #include <sstream> using namespace std ; int main() { string str ; getline( …

Member Avatar for Mac.Z
0
318
Member Avatar for tech291083

[quote=tech291083;350286]Thanks, Fully agree with your reply, but I just want to see if it is possible to tell the compiler to display the number/output in a manner (with all the zeros/digits in it) that one wants to. Cheers...[/quote] [code] stm << fixed << setprecision(200) << number << '\n' ; [/code] …

Member Avatar for Salem
0
398
Member Avatar for jerryseinfeld

[quote=jerryseinfeld;348623]last question :( I heard some bubblesort thing.. what is it.. is it suitable for me???[/quote] yes jerry, it would be very suitable for you. you would enter the struct (with name, year, doctor, illness as member variables) into an array and use a bubble sort (not the best sort …

Member Avatar for Ancient Dragon
0
222
Member Avatar for addicted

[quote=addicted;349316]If yes, Help with the declaration[/quote] [code] template< typename T > inline void swap( T& a, T& b ) ; // declaration (function) template< typename T, size_t N > struct array ; // declaration (class) // definition of function template< typename T > void swap( T& a, T& b ) …

Member Avatar for vijayan121
0
87

The End.