1,247 Posted Topics

Member Avatar for AutoC

Parse the type string (int, char, float etc.) and the data in text form into strings. If the possible types are known before hand, a simple if/else if construct would do the job. [CODE]#include <string> #include <vector> #include <boost/lexical_cast.hpp> #include <stdexcept> template< typename T > void do_push_back( std::vector<T>& v, const …

Member Avatar for Ancient Dragon
0
88
Member Avatar for RFBourquin

[url]http://msdn2.microsoft.com/en-us/library/ms533265.aspx[/url] [url]http://msdn2.microsoft.com/en-us/library/ms533235.aspx[/url]

Member Avatar for 7sedam7
-1
2K
Member Avatar for Pynolathgeen

See [url]http://weblogs.asp.net/kennykerr/archive/2008/01/03/parallel-programming-with-c-part-4-i-o-completion-ports.aspx[/url]

Member Avatar for vijayan121
0
108
Member Avatar for Rishikeshan

Add a const qualifier to the string in [ICODE]void *getfile( string url, [COLOR="Red"]const[/COLOR] char *file );[/icode] [B]CUROPT_URL[/B] requires a c-style string for the url. [ICODE]curl_easy_setopt(curl, CURLOPT_URL, [COLOR="Red"]url.c_str()[/COLOR] );[/ICODE]

Member Avatar for vijayan121
0
216
Member Avatar for lytnus

[QUOTE]Templating allows me to fill that vector with anything, not just classes derived from Node, which could screw things up. As such, this seems like a sloppy and potentially error-prone workaround.[/QUOTE] Use SFINAE to restrict the types to just Node or derived classes of Node. [QUOTE]Also, in the example, AddValues() …

Member Avatar for lytnus
0
292
Member Avatar for ftl25

> The problem lies in the declaration of the lookup table. > All the functions are already defined in an external DLL, and I can't touch them. So write wrappers of your own that call the functions in the DLL. > The problem now is that the "WriteMemory" commands take …

Member Avatar for vijayan121
0
2K
Member Avatar for VBNick

> you have to make sure is the the second thread is not just constantly checking the state The efficient (and elegant) way to do this is to use a condition_variable. [url]http://www.boost.org/doc/libs/1_42_0/doc/html/thread/synchronization.html#thread.synchronization.condvar_ref[/url]

Member Avatar for mike_2000_17
0
187
Member Avatar for Stefano Mtangoo

> I want default value to be NULL so that whenever I encounter NULL > I know that there is no implementation for this function. > I wonder If NULL will be suitable for function that returns some type of value There are two ways that you can simulate this …

Member Avatar for Stefano Mtangoo
0
130
Member Avatar for embooglement

Change [B]std::stringstream&[/B] to [B]std::ostream&[/B] in the overloaded operator and you would be ok. [CODE]class A { public: int num; A(int x) : num(x) {}; friend [COLOR="Red"]std::ostream&[/COLOR] operator<<( [COLOR="Red"]std::ostream&[/COLOR] stream, const A& someobject ); }; [COLOR="Red"]std::ostream&[/COLOR] operator<<( [COLOR="Red"]std::ostream&[/COLOR] stream, const A& someobject ) { stream << someobject.num; return stream; };[/CODE] Why …

Member Avatar for embooglement
0
2K
Member Avatar for bleedi

> now that I've opened my eyes, the crash happens when I try to handle the objects contained in the vector. If you open your eyes a wee bit more, you would also notice that after [ICODE]delete temp ;[/ICODE] the vector contains (a copy of) a pointer which points to …

Member Avatar for mrnutty
0
132
Member Avatar for psuspect

modify the function to [code] int countchar( const char list[], char what ) { int i=0, count=0 ; for( ; list[i] != 0 ; ++i ) if( list[i] == what ) ++count ; return count ; } [/code]

Member Avatar for bluntaxe1
0
538
Member Avatar for Bigbrain99

Use include guards. [url]http://en.wikipedia.org/wiki/Include_guard[/url] [url]http://www.steveheller.com/cppad/Output/homeward6.html[/url]

Member Avatar for Bigbrain99
0
90
Member Avatar for Nathaniel10

IIRC, the a subsequent chapter of the book deals with completing this program. You would learn there about most of these issues (input and output, modulus operations, recovering from errors and so on), and be asked to refine the first draft of the program. So, perhaps the intent is to …

Member Avatar for Nathaniel10
2
141
Member Avatar for jheichimiste

For C++, you could base the course on Stroustrup's 'Software: Principles and Practice Using C++'. This is a book that is based on a course he designed for engineering freshmen at Texas A&M U. The support site for the book [url]http://www.stroustrup.com/Programming/[/url] also has some content for teachers - Instructor's Guide, …

Member Avatar for Stefano Mtangoo
0
104
Member Avatar for umesh314

If you are just starting out on C++, these two would be high on the list of books: Stroustrup's 'Programming: Principles and Practice using C++' [url]http://www.stroustrup.com/Programming/[/url] Koenig and Moo's 'Accelerated C++: Practical Programming by Example' [url]http://www.acceleratedcpp.com/[/url]

Member Avatar for umesh314
0
157
Member Avatar for daviddoria

> That is the whole problem - I am not allowed to [B]#include <vector>[/B] in any header file You don't have to [B]#include <vector>[/B] in any header file, you just have to declare [B]std::vector<>[/B] in the header. 1. Declare [B]std::vector<>[/B] in [B]Myclass.h[/B] 2. [B]#include <vector>[/B] (define [B]std::vector<>[/B]) in MyClass.cc and …

Member Avatar for daviddoria
0
262
Member Avatar for HumanBeing86

[CODE]class Cat : public Animal{ double weight; public: Cat(string name, double weight) : Animal(name), weight(weight) {this-> weight = weight;} void print() const { [COLOR="Red"]Animal::print() ;[/COLOR] [COLOR="Green"]// *** added *** [/COLOR] cout << "Weight = " << weight << endl; }[/CODE]

Member Avatar for vijayan121
0
152
Member Avatar for Bench

> My first question is why is static used? > My understanding is that static objects are instantiated once and persist untill the end of the program In this particular case specifying a static storage duration does not make any perceptible difference. [CODE]int main() { int a[] = { 7, …

Member Avatar for vijayan121
0
2K
Member Avatar for yup790

[CODE]#include <iostream> template < int N > struct S : S<N-1> { S() { if( std::cout << N << ". Hello World\n" ) {} } }; template <> struct S<0> {} ; int main() { S< sizeof("twenty Hello Worlds") >() ; } [/CODE] > Try this one on for size... …

Member Avatar for mrnutty
0
221
Member Avatar for sbrohee
Member Avatar for Allophyl

> As far as I understand, each node in a list contains an element as well as pointers to both the following and preceding elements. > Both an integer and a pointer to an integer are 4 bytes, so one would think that a node would use up 12 bytes, …

Member Avatar for vijayan121
0
163
Member Avatar for sparton

[url]http://www.icce.rug.nl/documents/cplusplus/[/url] [url]http://www.informit.com/guides/content.aspx?g=cplusplus[/url] [url]http://www.devx.com/cplus/Door/7042[/url] [url]http://www.cprogramming.com/tutorial.html[/url] [url]http://www.cplusplus.com/doc/tutorial/[/url] [url]http://www.learncpp.com/[/url]

Member Avatar for vijayan121
0
64
Member Avatar for pc0019

> Out of curiosity, is this even possible? Something like this would be possible in C++0x (after a constructor that takes a [icode]std::initializer_list<>[/icode] is added to the ublas matrix). [ICODE]boost::numeric::ublas::matrix mtx { {1,1,1}, {2,2,2}, {3,3,3} } ;[/ICODE] Right now, one work around would be to put the initializers for the …

Member Avatar for vijayan121
0
118
Member Avatar for drjay1627

> Is there any way of checking all elements in a queue without calling pop(). Yes, if you have used a [icode]std::queue<T>[/icode] with the default [icode]std::deque<>[/icode] for the second template parameter. [CODE]template< typename T > void foobar( const std::queue<T>& queue ) { typename std::deque<T>::const_pointer begin = &queue.front() ; typename std::deque<T>::const_pointer …

Member Avatar for vijayan121
0
129
Member Avatar for sksingh73

[B]> man setsockopt[/B] Or if you are not on Unix, see: [url]http://www.freebsd.org/cgi/man.cgi?query=setsockopt&apropos=0&sektion=0&manpath=FreeBSD+8.1-RELEASE&format=html[/url] And then look for the option [B]SO_RCVTIMEO[/B]

Member Avatar for vijayan121
0
91
Member Avatar for Lord_Migit

[CODE]else { if(j >= i) //this small section makes sure that 'i' cant breed with itself and the selection is corrected for array re-arrangement [COLOR="Red"]// Don't we need to recalibrate the roulette wheel here?[/COLOR] iPopulation[iPopDensity - 1][iChromeLength + 2] = j + 1; else // ... }[/CODE]

Member Avatar for vijayan121
0
393
Member Avatar for Garrett2011

> can we pass arrays to functions You couldn't pass arrays to functions in C, and couldn't pass them in C++98 either. And you won't be able to do that in C++0x too. However, in C++0x you could pass a [icode]std::initializer_list<>[/icode] to a function; that is what [icode]someFunction({{1,2},{3,4},{5,6}});[/icode] attempts to …

Member Avatar for vijayan121
0
262
Member Avatar for wwefriend

> i am not understanding about ,Preprocessor,Compiler ,linker , Loader ,CPU If you are just starting out, don't bother all that much about the gory details of what these different entities are right now. Just get a rough idea of what #include means, write the first hello world program, compile …

Member Avatar for wwefriend
0
135
Member Avatar for Nandu Das
Member Avatar for vijayan121
0
70
Member Avatar for Garrett2011

AFAIK, the main advantage of nested functions in languages that have them is to provide support for closures. [url]http://en.wikipedia.org/wiki/Closure_%28computer_science%29[/url] [quote]Closures typically appear in languages that allow functions to be first-class values, in other words, such languages allow functions to be passed as arguments, returned from function calls, bound to variable …

Member Avatar for arkoenig
0
533
Member Avatar for racoon8995

> Thats exactly What I meant. put the declarations in the *.cpp file and it'll work. For starters, that will be a gross violation of ODR. see: [url]http://en.wikipedia.org/wiki/One_Definition_Rule[/url] You could of course write your own string class, and use it in any way that you please, as long as you …

Member Avatar for vijayan121
0
173
Member Avatar for dansnyderECE

Don't really know what you are up to, but are you looking for something like this? [CODE]#include <iostream> #include <string> #include <cassert> #include <stdint.h> // C99, <cstdint> in C++0x uint64_t as_number( const std::string str ) { const unsigned int MAX_BYTES = sizeof(uint64_t) ; assert( str.size() <= MAX_BYTES ) ; union …

Member Avatar for vijayan121
0
220
Member Avatar for TheWeakGetEaten

you need to have a user defined type for performing arithmetic operations (atleast a plus) on integers with large precision. either write a big_integer class or use a library eg:class bigint from the LiDIA library ([URL]http://www.cdc.informatik.tu-darmstadt.de/TI/LiDIA/[/URL])

Member Avatar for bondgirl
0
1K
Member Avatar for superjacent

> I was creating the derived class method definitions in a cpp file > and couldn't get the project to progressively compile correctly. > At my first method definition, a default constructor, > the compiler kept spitting out this error message: this is perhaps the most obscure error message that …

Member Avatar for sheldonrobinson
1
59K
Member Avatar for Garrett2011

[CODE] class Test{ public: Test()=default; Test(char in1,char in2):char1(in1),char2(in2){} char char1; private: char char2; }; Test obj={'a','b'};//invalid in c++0x [/CODE] It is valid in C++0x. The final proposal is here: [url]http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2640.pdf[/url]

Member Avatar for Garrett2011
0
292
Member Avatar for Garrett2011

> which kinds of constructors can be applied during compile time ? None in C++98; though constructors can be elided as in the case of RV optimization. Objects constructed via the the constexpr mechanism in C++0x. [url]http://www2.research.att.com/~bs/C++0xFAQ.html#constexpr[/url]

Member Avatar for Garrett2011
0
403
Member Avatar for Garrett2011

Typically it doesn't, unless you force it to. For example: [CODE]> g++44 -Wall -std=c++98 -pedantic -Werror -fomit-frame-pointer -fstrict-aliasing -fconserve-stack -fno-defer-pop[/CODE] The frame of a function is transient, and the memory is reclaimed as soon as the function returns. It could also cause most debuggers to stumble.

Member Avatar for Garrett2011
0
422
Member Avatar for ThrasherK

> Why does C++ seem more complicated than Visual Basic? Because it *is* more complicated than Visual Basic. But you don't need to be extraordinarily brilliant to learn C++ and to use C++ effectively. Almost all programmers who make a genuine attempt to become good C++ programmers do succeed in …

Member Avatar for Fbody
0
677
Member Avatar for merse

[B]isnan()[/B] is from C99; and is not part of C++98. See [url]http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.15[/url] In C++0x, [B]isnan()[/B] is part of TR1. You could easily roll out isnan() and isinf() on your own, though: [CODE]#include <limits> template< typename T > inline bool isnan( T value ) { return value != value ; } …

Member Avatar for merse
0
182
Member Avatar for dansnyderECE

> I asserted the flag -static-libgcc on compilation of my hello.cpp file (hello world program). > Apparently this is not enough though. Because there is still a segment in my executable which contains the name/path of the dynamic loader. > What flags do I use to generate an executable which …

Member Avatar for vijayan121
0
2K
Member Avatar for Kanoisa

> as far as i understand the if statment should stop evaluating if the first condition is false > [as it is an && operation] (ie no player occupies the seat, therefore the pointer is invalid) > so it should not try to evaluate the player->inRound bit Your understanding is …

Member Avatar for Kanoisa
0
118
Member Avatar for group256

Use [icode]std::getline[/icode] to read line by line. Use a [icode]std::istringstream[/icode] to extract the words in the line. [code]while( std::getline( file, line ) ) // read line by line { if( line == "" ) // just a '\n' in file { // an empty line, new paragrah logic } else …

Member Avatar for vijayan121
0
163
Member Avatar for neil_mahaseth

Use [icode]std::vector<bool>[/icode] for space efficiency (if N is large). And [icode]std::transform[/icode] and [icode]std::count[/icode] for programmer efficiency. [code]#include <iostream> #include <vector> #include <functional> int main() { const bool TAIL = false, HEAD = true ; enum { FLIP_THEM = 0, COUNT_HEADS = 1 } ; std::vector<bool>::size_type N, Q ; std::cin >> …

Member Avatar for neil_mahaseth
0
144
Member Avatar for ivareske

Open the stderr log file for writing (with [icode]CreateFile[/icode]). Call [icode]SetStdHandle( STD_ERROR_HANDLE, log_file_handle ) ;[/icode] to redirect stderr for the process to the log file.

Member Avatar for vijayan121
0
172
Member Avatar for TurboCoding

Write a constructor for A [code]class A { public: A( /* ... */ ) : fv( length, fix_fac ) {} private: fixvec fv ; };[/code]

Member Avatar for TurboCoding
0
166
Member Avatar for hg_fs2002

> I have the number of paragraphs and now I want to store the number of lines in each paragraph in a vector. You do not need to calculate these separately - once you have the number of lines in each paragraph in a vector, the [icode]size()[/icode] of the vector …

Member Avatar for vijayan121
0
96
Member Avatar for dansnyderECE

For MIPS, each ELF object module keeps track of its own OMF flags. The linker copies the appropriate flags from the original object module; if two different files have different sets of flags, unless they are conflicting flags, the more restrictive one is applied and a dignostic is generated: "xxx.o …

Member Avatar for vijayan121
0
556
Member Avatar for Andreas5

> My operator+= works > However i cant get the operator+ to work The problem seems to be in your copy constructor; operator+ needs to make a copy. First, verify that the copy constructor [icode]Str2::Str2( const Str2& )[/icode] is working correctly.

Member Avatar for Andreas5
0
93
Member Avatar for gretty

> warning C4293: '<<' : shift count negative or too big, undefined behavior 56, 48, 40 are greater than the number of bits in an int on the implementation you are using (which seems to have a 32 bit int). Convert (or cast) to a 64 bit integral type first. …

Member Avatar for archana.c07
0
2K
Member Avatar for ischuldt
Member Avatar for arkoenig
0
124

The End.