1,247 Posted Topics

Member Avatar for rakeshk_87

> how to read input from strings using cin 1. Create a [b]std::stringbuf[/b] which gets its input from a [b]std::string[/b]. 2.Set this as the [b]std::streambuf[/b] used by [b]std::cin[/b] [code]#include <iostream> #include <string> #include <sstream> int main() { std::string input_string = "string containing input 123 45 a 72.45 etc." ; std::stringbuf …

Member Avatar for rakeshk_87
0
241
Member Avatar for foco

The result of a [b]typeid[/b] expression is a [b]std::typeinfo[/b] object representing the *type* of the expression. Type of temp is an int, so [b]typeid(temp)[/b] and [b]typeid(4)[/b] both give [b]typeid(int)[/b]. To check if the user entered an int or not, check the state of the stream after the attempted input. If …

Member Avatar for vijayan121
0
94
Member Avatar for sofia24

[code=c++]std::ifstream file( "filename.txt" ) ; std::string line ; while( std::getline( file, line ) ) { // parse the line which was just read }[/code]

Member Avatar for Taywin
0
421
Member Avatar for iamcreasy

Specify std::ios::ate as the file mode in the constructor. Or if the file is already open, close it and reopen with std::ios::ate as the file mode.

Member Avatar for iamcreasy
0
183
Member Avatar for iamcreasy
Member Avatar for MaestroS

you do not have to make one. it is available in libraries. either the boost string algorithms or the boost tokenizer could be used. here is an example using the boost string algorithms split. as you can notice, c++ libraries are far more powerful and expressive. in this example, we …

Member Avatar for Stefano Mtangoo
0
887
Member Avatar for tennis

A simple way: [code]struct A { static A* create() { return new A() ; } // ... private: A( /* ... */ ) ; A( const A& that ) ; // ... };[/code]If that is too simple for your requirements, see: [i]Item 27: Requiring or prohibiting heap-based objects[/i] in 'More …

Member Avatar for Radical Edward
0
110
Member Avatar for MaximNM

std::sort is an overloaded function, and this can cause problems with some compilers. see: [url]http://www.boost.org/doc/libs/1_37_0/libs/bind/bind.html#err_overloaded[/url] The work-arounds are simple; this is one way: [code]typedef std::vector<int>::iterator iterator ; void (*sort_function)( iterator, iterator ) = &std::sort ; thg.create_thread( boost::bind( sort_function, mass.begin(), mass.end() ) ;[/code]

Member Avatar for MaximNM
0
351
Member Avatar for Ico.I.Am

To export symbols from a shared library, you need to use the [b]__declspec(dllexport)[/b] attribute as you have done. A program that uses exported symbols from a DLL needs to import them using [b]__declspec(dllimport)[/b]. It is usually a good idea to have a single header file for the shared library, which …

Member Avatar for vijayan121
0
114
Member Avatar for iamthwee

This is how I would do it. O(N log N) time. a. Keep track of the line number as the lines are read into a vector. b. Sort on the string (part that is to be checked for duplicates) c. Partition into unique and non-unique lines (on the string) d. …

Member Avatar for iamthwee
0
280
Member Avatar for dimios

This paper by Stroustrup addresses some of the issues raised in this thread. Well worth a read, IMHO. [url]http://www.research.att.com/~bs/new_learning.pdf[/url]

Member Avatar for bandtank
0
221
Member Avatar for iamthwee

> Size and speed aren't really an issue here, just ease of use. > Using std::strings as well would be beneficial. You might want to have a look at TinyXML. [url]http://www.grinninglizard.com/tinyxml/[/url] And perhaps TinyXML++, which leverages more C++ strengths. [url]http://code.google.com/p/ticpp/[/url]

Member Avatar for scrontch
1
234
Member Avatar for trantran

> Is there a safe and legal way to go from a pointer to a member of an object > to a pointer to that same object? No. A pointer to a member is a pointer to a member of a class, not a pointer to a member of an …

Member Avatar for trantran
0
130
Member Avatar for goulda660

Define the static member variables that have been declared. [CODE] namespace fun{ // ... class driver{ // ... static int size; static int eff; static int idnumber; static std::vector<int> bmv; static std::vector<int> amv; static std::vector<int> bbv; static std::vector<int> abv; // ... }; // ... } // ... int fun::driver::size = …

Member Avatar for goulda660
0
176
Member Avatar for duke.tim

> error: ‘numeric_limits’ was not declared in this scope #include <limits> > error: ‘streamsize’ was not declared in this scope std::streamsize

Member Avatar for duke.tim
0
717
Member Avatar for cproud21

Yes, this is typically done using a monitor (aka condition variable). See: [url]http://en.wikipedia.org/wiki/Monitor_%28synchronization%29[/url] And: [url]https://computing.llnl.gov/tutorials/pthreads/#ConditionVariables[/url]

Member Avatar for vijayan121
0
239
Member Avatar for JwhateverJ

> But how do I go thru A folder and get all the files size's that are inside? See: [url]http://www.daniweb.com/forums/post342872.html#post342872[/url] That just prints the native_file_string. To get the file size, construct a [b]boost::filesystem::path[/b] from [b]iter->native_file_string()[/b] and then use [b]boost::filesystem::file_size[/b] on it, as in your current code.

Member Avatar for JwhateverJ
0
4K
Member Avatar for eDeloa

> Could you refer me to a site that explains exactly why it can't be initialized inside the class definition? I'd like to read up on the working behind why this is. [CODE]class Test { public: static const string MYARRAY[] ; // only a declaration };[/CODE] [CODE]class Test { public: …

Member Avatar for kvprajapati
0
2K
Member Avatar for godflesh231

In this function [CODE]CEntityFactoryDictionary EntityFactoryDictionary( ) { static CEntityFactoryDictionary s_EntityFactoryDictionary; return s_EntityFactoryDictionary; } [/CODE] You are returning (by value) an anonymous temporary object which is a copy of the static s_EntityFactoryDictionary; you call InstallFactory on this anonymous temporary object which is immediately destroyed after that. Modify the function as: [CODE]CEntityFactoryDictionary[COLOR="Red"][B]&[/B][/COLOR] …

Member Avatar for godflesh231
0
123
Member Avatar for bgx90

1. Declare each template friend function before the definition of template class. (#include of the header, as you have will do). 2. Add [b]<>[/b] in the friend declarations. [code]template <class T> class UList ; template <typename T > void sort( UList<T>& ) ; template <typename T > std::ostream& operator << …

Member Avatar for bgx90
0
237
Member Avatar for FinalDecap

Write three 'main' functions, one in each file. [code] int ProgramList_main( int argc, char** argv ) ; int MD5Hash_main( int argc, char** argv ) ; int HazardCheck_main( int argc, char** argv ) ; [/code] Then write a single real main function, which calls these one after another: [code] int main( …

Member Avatar for FinalDecap
0
221
Member Avatar for euclid135

Instead of defining it here, as [code] int map[ MAP_WIDTH * MAP_HEIGHT ] = { // ... }; [/code] Just declare it in this file [code] extern int map[] ; [/code] (And then define it in the implementation file of area, eg. area.cc)

Member Avatar for euclid135
0
499
Member Avatar for artikapri

See [url]http://home.netcom.com/~chip.f/viterbi/tutorial.html[/url] And [url]http://www.eccpage.com/[/url]

Member Avatar for vijayan121
0
129
Member Avatar for kyle11778

Well, you could start with these two and then follow the links given in them. [url]http://antivirus.about.com/od/whatisavirus/a/virussignature.htm[/url] [url]http://en.wikipedia.org/wiki/Anti-virus_software[/url]

Member Avatar for vijayan121
0
77
Member Avatar for chidambaram

[ICODE]gethostname[/ICODE] will give you the name of the current host [ICODE]gethostbyname[/ICODE] looks up the host with a particular name and will give you the address > [ICODE]man 3 gethostname[/ICODE] > [ICODE]man 3 gethostbyname[/ICODE]

Member Avatar for samar ihab
0
313
Member Avatar for gnarlyskim

[code]void Example::function1( const Example& ex ) { Example copy_of_ex( ex ) ; /* whatever */ }[/code]

Member Avatar for gnarlyskim
0
127
Member Avatar for Anand111

Windows operating systems: Write your program and run it as an NT service [url]http://www.commsoft.com/services.html[/url] Unix and unix like operating systems: Daemonize your program and run it as a unix daemon. [url]http://www.enderunix.org/docs/eng/daemon.php[/url]

Member Avatar for vijayan121
0
81
Member Avatar for sana zafar

Change line 32 to use [b]fabs[/b] instead of [b]abs[/b] (why?) [code]while ( fabs(high - low) > epsilon ) { [/code] Ideally, also change the type of all the floating point numbers to [b]double[/b] instead of [b]float[/b] (why?) And you should be ok.

Member Avatar for vijayan121
0
142
Member Avatar for n.utiu

[code]class cIsBad : public [color=red][b]std::[/b][/color]unary_function <T, bool> {[/code]

Member Avatar for n.utiu
0
113
Member Avatar for gcochra1

use [b]std::find_if[/b] to locate the right position to insert the new item. For example: [code]#include <iostream> #include <functional> #include <algorithm> #include <list> #include <iterator> struct Ctest { Ctest( double fv ) : fVal(fv) /* .... */ { /* ... */ } // ... [color=red][b]bool operator > ( const Ctest& that …

Member Avatar for Lerner
1
104
Member Avatar for trantran

Are you looking for something like this? [code]template< typename T > struct list { T* current ; }; template< typename T, T* T::*PTRMEMBER > T* get_next( list<T>& lst ) { lst.current = lst.current->*PTRMEMBER ; return lst.current ; } struct A { A* member_one ; A* member_two ; }; int main() …

Member Avatar for trantran
1
565
Member Avatar for edek

there is no readily available facility in the standard library to do this. however, the library is designed to be extensible: so we can easily write our own stream/streambuf derived classes. the Boost.Iostreams library does contain stream/streambuf derived classes which use a file descriptor/HANDLE. Boost is widely portable, so we …

Member Avatar for Freaky_Chris
0
465
Member Avatar for sean108

you could try ncurses [url]http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/intro.html#WHATCANWEDO[/url]

Member Avatar for kendapcwiz
0
519
Member Avatar for riotburn

See: [url]http://docs.sun.com/source/806-3568/ncg_goldberg.html[/url] You might want to use a library like MPFR (a multiple-precision floating-point computations library with correct rounding). A C++ wrapper would be convenient. There are several, you can find one of them here: [url]http://beshenov.ru/mpfrcpp/[/url]

Member Avatar for riotburn
0
119
Member Avatar for vijayan121

Question posed by josolanes: [quote]I looked at your thread here: [url]http://www.daniweb.com/forums/thread88255.html[/url] from a couple years back And I'm starting to get a grasp of your first post. I understood how to do the factorial struct really quickly, but the _if and _for statements still make me feel uneasy, though I …

Member Avatar for josolanes
1
170
Member Avatar for Web_Sailor

> Its printing only the first elements Well, you have a multimap which contains multimaps : [b]multimap<string,multimap<string,int> > mymm;[/b] So you need a nested loop to print the contents of the inner multimaps. Something like: [code]for (itx = mymm.begin(); itx != mymm.end(); ++itx) { cout << " [" << itx->first …

Member Avatar for Web_Sailor
0
151
Member Avatar for emilo35

Couple of general points: In general use references (instead of pointers) for strings, streams and the like. Use const where ever and whenever possible - it is your friend. Prefer using '\n' to std::endl to send a new line to a stream, unless your intent is to also flush the …

Member Avatar for emilo35
0
184
Member Avatar for Buttacup

Export members selectively from your dll: [code]class my_class { public: void foo() ; // not exported __declspec(dllexport) void bar() ; // exported }; void my_class::foo() {} __declspec(dllexport) void my_class::bar() {}[/code] And import them selectively in places where you want to use it: [code]class my_class { public: void foo() ; // …

Member Avatar for Buttacup
0
267
Member Avatar for Stefano Mtangoo

Use something like [b]std::vector< boost::any >[/b] [url]http://www.boost.org/doc/libs/1_37_0/doc/html/any.html[/url]

Member Avatar for Stefano Mtangoo
0
87
Member Avatar for dilas

Either of these two is the right way to declare C::foo<> as a friend. [code]struct C { template < bool B > void foo() ; template< bool B > class B { // ok, the compiler already knows that C::foo // is a template function friend void C::foo() ; // …

Member Avatar for dilas
1
165
Member Avatar for Kikazaru

> What is this thingy that I'm trying to name or whatever? Well, it is part of the IS, under section 7.1.5.1 'The cv-qualifiers' [quote]A variable of const-qualified integral or enumeration type initialized by an integral constant expression can be used in integral constant expressions - IS 7.1.5.1/2 A pointer …

Member Avatar for vijayan121
0
3K
Member Avatar for eliza420

alternatively, [code] std::ifstream file("filename") ; std::istream_iterator<std::string> begin(file), end ; if( find( begin, end, "Computer" ) != end ) // found [/code]

Member Avatar for Fbody
0
170
Member Avatar for sexyzebra19

Rewrite [inlinecode]void Matrix::Multiply(Matrix b) ;[/inlinecode] as [inlinecode]Matrix Matrix::Multiply( const Matrix& b ) const ;[/inlinecode] In the implementation, do not modify either of the two Matrix objects involved in the multiply. Construct a new result Matrix object of the appropriate size, populate it and return it. Ok, I see that Dragon …

Member Avatar for sexyzebra19
0
96
Member Avatar for cog_bn

A good implementation of the vector would call the copy constructor when memory is reallocated. Invoking the default constructor first and then the assignment operator has an efficiency issue. Note: C++0x containers would use move semantics (instead of copy semantics) if they are available on the object. Modify the code …

Member Avatar for vijayan121
0
636
Member Avatar for RooiBaard

[b]std::transform[/b] is perhaps what you are looking for. [url]http://www.cppreference.com/wiki/stl/algorithm/transform[/url]

Member Avatar for vidit_X
0
125
Member Avatar for clutchkiller

> obj.baseInfo::SlotCount[0] = 5; > This compiles fun but gives me an error after running it. It should not compile (though IIRC, microsoft compilers just give a warning that memory would be corrupted and proceed to generate incorrect code that will corrupt the memory - on the stack in this …

Member Avatar for clutchkiller
0
94
Member Avatar for SonxQ7

Most, but not all, Boost libraries are header-only libraries; most often, there's nothing to build. However, a few libraries must be built separately. Boost DateTime has a binary component that is needed if you're using its to_string/from_string or serialization features. If you do not have the binaries installed, you need …

Member Avatar for vijayan121
0
516
Member Avatar for kevintse

In general, if you're displaying error messages to the user based on what() of an exception that was thrown, you are probably doing something wrong. The code that throws an exception is very unlikely to be able to compose a relevant and user-comprehensible error message at the point an exception …

Member Avatar for kevintse
0
3K
Member Avatar for Gaurav arora

[quote=joeprogrammer;340533] [inlinecode]endl[/inlinecode] is not a character, it's a macro which: a) inserts a newline '\n' into the output buffer b) flushes the output buffer. [/quote] endl is a function [code] template<typename CHARTYPE, typename TRAITS> [URL="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/classstd_1_1basic__ostream.html"][/URL] basic_ostream<CHARTYPE,TRAITS >& endl( basic_ostream<CHARTYPE,TRAITS>& stm ) { stm << '\n' ; returm stm.flush() ; } …

Member Avatar for ashutosh1234
0
99
Member Avatar for programmer01

modify the signature of these two functions: [code]double Value_Of_Num( [COLOR="Red"]const[/COLOR] string &Expr ) ; double Value_Of_Expr( [COLOR="Red"]const[/COLOR] string &Expr ) ;[/code] or a comforming compiler will give you errors. you can't initialize a reference to a modifiable value with an anonymous temporary (deemed to be a constant). > The problem …

Member Avatar for Naira88
0
2K

The End.