1,247 Posted Topics

Member Avatar for see_bharath

Enable ISO C++ conformance (eg. --std=c++0x -pedantic) and warning messages (eg. -Wall). [CODE]char * s = "hello world";[/CODE] would have made the compiler emit a diagnostic - something like "[B]warning: deprecated conversion from string constant to char*[/B]".

Member Avatar for Schol-R-LEA
1
307
Member Avatar for Raisefamous

You need to add [B]Sally.cpp[/B] to the project. Menu: Project->Add Files ... IIRC.

Member Avatar for Raisefamous
0
223
Member Avatar for Chuckleluck

[B]ntdll.dll[/B] etc. are system library files; the PDB files for these are required only if you want to debug system library function calls. You can safely ignore these warnings. You might want to add a line so that the program would wait for an input at the end: [CODE]int main() …

Member Avatar for Chuckleluck
0
490
Member Avatar for sania khan

Without using arrays and without using strings? That makes it interesting. Something like a linked list would obviously work, but perhaps storing each character in the local frame of a (recursive) function would be the simplest. [CODE]#include <iostream> void read_and_print_reverse() { char c = std::cin.get() ; if( c != '\n' …

Member Avatar for vijayan121
0
371
Member Avatar for Dman01

> While I'm inserting such entity in a std::map the code fails and makes the program crash. > Because I can suppose it's a error from one of my class The crash doesn't seem have anything to do with inserting into a [B]std::map<>[/B] per se. a. in [B]void EntityManager::RegisterEntity( BaseGameEntity* …

Member Avatar for Dman01
0
3K
Member Avatar for kbar1

> Or something purely mathematical. A problem in combinatorics. A sequence of [B]N[/B] integers contains the numbers [B][1,N][/B] in some random order. For example: [code]enum { N = 25 } ; std::vector<int> seq ; for( int i = 0 ; i < N ; ++i ) seq.push_back(i+1) ; // the …

Member Avatar for mike_2000_17
0
161
Member Avatar for Labdabeta

A couple of points: 1. In the dll implementation, preferrably [B]#define BUILD_DLL[/B] prior to including the header file. 2. Writing [B]DllMain[/B] is optional; if there is nothing special you need to do you can omit it, and the library gives a default implementation. 3. Unless your design intent is to …

Member Avatar for Labdabeta
0
155
Member Avatar for MrEARTHSHAcKER

> I have the array of objects of structure, and wished to point to it over the pointer > which already points to it ( pointer to pointer to array of objects. ). > Confusing? Using a few typedefs would help eliminate the confusion: [code]int main() { struct person{ int …

Member Avatar for MrEARTHSHAcKER
0
201
Member Avatar for BCBTP

> I was wondering if anyone has some good examples of running python functions and scripts > within C++ using the Python C API. Python documentation has a simple example: [url]http://docs.python.org/extending/embedding.html[/url] Another simple example: [url]http://code.google.com/p/kanghtta/source/browse/trunk/Python/Demo/embed/demo.c?r=16[/url] Somewhat more involved: [url]http://www.codeproject.com/KB/cpp/embedpython_1.aspx[/url] > What are some ways to use python in C++ programs, …

Member Avatar for vijayan121
0
318
Member Avatar for Chuckleluck

Put the class definition in a header file of its own and include that header in other translation units. See: [url]http://www.informit.com/articles/article.aspx?p=26039[/url]

Member Avatar for Chuckleluck
0
188
Member Avatar for Zssffssz

> In gcc 3.4.6, it gives a Warning: > warning: this decimal constant is unsigned only in ISO C90 Ideally, use a more recent version of the compiler (ie. not older than the oldest maintained release). For precise control over the integral type on which enums are based, use scoped …

Member Avatar for vijayan121
0
147
Member Avatar for Raisefamous

> My knowledge about C++ and programming so far is 27 youtube videos. > It took me 1,5 hours to figure out and write this Pretty good first effort, I would say. Well done! Relying on youtube videos alone might not be a good idea; get a text book too. …

Member Avatar for WaltP
0
259
Member Avatar for Vasthor

> well, I posts this because when I search internet for the difference between for and while, > many people say it work the same and tell that the only difference is the form. These two are equivalent:[CODE]for( int i = 0 ; i < 10 ; ++i ) {} …

Member Avatar for Vasthor
0
247
Member Avatar for Labdabeta

> It has no effect For standard types, a unary [B]+[/B] always yields an r-value.[CODE]unsigned short s = 8 ; unsigned short& r = s ; // s is an l-value unsigned short&& rvr = +s ; // +s yiels an r-value[/CODE] For standard types, a A unary [B]+[/B] performs …

Member Avatar for mrnutty
0
301
Member Avatar for sangkun

`s[i] + s[i+1] + s[i+2];` would just do an integral addition of the three char values; instead you need to make a `std::string` of three chars. I suppose `for (int i=0; i < s.length() - 2; i+3)` is a typo; should be `for( int i=0 ; i < s.length() - …

Member Avatar for vijayan121
0
1K
Member Avatar for stereomatching

For Spirit to be able to parse data directly into a class/struct/union, a fusion adapter is required. See: [url]http://www.boost.org/doc/libs/1_48_0/libs/spirit/doc/html/spirit/qi/tutorials/employee___parsing_into_structs.html[/url] For [B]std::pair<>[/B] support, just: [ICODE][B]#include <boost/fusion/include/std_pair.hpp>[/B][/ICODE] which would pull in (along with some other stuff) [ICODE]BOOST_FUSION_ADAPT_STRUCT( std::pair, ( std::string, first ), ( std::string, second ) ) ; [/ICODE]

Member Avatar for stereomatching
0
287
Member Avatar for Dman01

Karatsuba, perhaps? [url]http://en.wikipedia.org/wiki/Karatsuba_algorithm[/url] [url]http://mathforum.org/library/drmath/view/71637.html[/url] C: [url]http://ozark.hendrix.edu/~burch/proj/karat/karat.txt[/url] (read the copyright notice.)

Member Avatar for Dman01
0
685
Member Avatar for jayanta87
Member Avatar for vijayan121
0
136
Member Avatar for jankeifer
Member Avatar for vijayan121
0
150
Member Avatar for pseudorandom21

[code]void foo( boost::asio::ip::tcp::iostream& stm ) { std::size_t bytes_available = stm.rdbuf()->available() ; // ... // the native socket descriptor can be retrieved for platform specific // socket functionality not available through asio. for example: auto fd = stm.rdbuf()->native_handle() ; // version 1.48. // IIRC, used to be stm.rdbuf()->native() earlier ::ifreq interface_request …

Member Avatar for vijayan121
0
181
Member Avatar for Arkinder

> My professor said this is useful in the event that your program is being "attacked." Useful, only if you are using C-style arrays of char. Don't create a problem that did not exist in the first place, and then try to solve it; just use [b]std::string[/b] instead. [b]std::string[/b] is …

Member Avatar for Arkinder
0
6K
Member Avatar for MrEARTHSHAcKER
Member Avatar for Xaviorin

> My intentions are to first take everything from the file into a variable, > then save everything from Start to the first comma minus the comma to a second variable, > and so on so forth till EOF where each string or value between commas is saved as a …

Member Avatar for Xaviorin
0
126
Member Avatar for iwlc

[QUOTE=;][/QUOTE] [b]SetConsoleScreenBufferSize()[/b] to a size that is not larger than the console window size. [url]http://msdn.microsoft.com/en-us/library/windows/desktop/ms686044%28v=vs.85%29.aspx[/url]

Member Avatar for vijayan121
0
3K
Member Avatar for Assassin7893

> Alternative once you have the index of the decimal point in the string, remove it, > reverse the string, and insert the decimal point back into the string Yes, Lerner. The simple way is the best way - if you want to manipulate text, treat it as text; if …

Member Avatar for Assassin7893
0
865
Member Avatar for metronomu

> Is the member variable from the base class renamed? No. There is no need to rename it; the fully qualified name of [b]x[/b] in [b]A[/b] is [b]A::x[/b] and the fully qualified name of [b]x[/b] in [b]B[/b] is [b]B::x[/b]. Normal scoping rules apply for name look up; if a name …

Member Avatar for metronomu
0
138
Member Avatar for BoBok2002

The [B]value_type[/B] of your stack (the type of elements it contains) is a fixed-size array. Define a member in your stack class to hold up to some max number of such elements, and keep track of the current logical size programmatically. Something like: [CODE]template< typename T, std::size_t ARRAY_SIZE, std::size_t MAX_STACK_SIZE …

Member Avatar for BoBok2002
0
1K
Member Avatar for jeevsmyd

> Is there any other way to make the system identify and pass the return type also ? > So that return type can also change dynamically depending on input. Ask the compiler to deduce what the appropriate return type is: [CODE]template< typename A, typename B > inline auto max_of( …

Member Avatar for mike_2000_17
0
225
Member Avatar for phorce

> ... then instead of inserting the (key, value) pairs in a map, insert the (value, key) pairs into a multimap. Would have to programmatically take care of the keys being unique, which makes it a bit messy. Use [B]Boost Bimap[/B], perhaps? [url]http://www.boost.org/doc/libs/1_48_0/libs/bimap/doc/html/index.html[/url] Something like: [CODE]#include <iostream> #include <boost/bimap/bimap.hpp> #include …

Member Avatar for vijayan121
0
135
Member Avatar for user543820

Use [b]std::istringstream[/b] [code]std::string str = "I have a dog" ; std::istringstream stm(str) ; string word ; while( stm >> word ) // read white-space delimited tokens one by one { // put word into array }[/code]

Member Avatar for user543820
0
6K
Member Avatar for hardingC

Or (slightly more efficient if there are a fair number of questions) generate a random sequence to determine the order in whick questions are to be asked. [code]int random_sequence[QUEST] ; for( int i=0 ; i<QUEST ; ++i ) random_sequence[i] = i ; std::random_shuffle( random_sequence, random_sequence+QUEST ) ; // <algorithm> for( …

Member Avatar for hardingC
0
173
Member Avatar for jefgreen

> Is it possible to have my table centered? Yes. See: [url]http://www.cprogramming.com/tutorial/iomanip.html[/url] > would it be possible to simply enter this data into my template at the bottom? > If so, how would I go about doing that? The standard C++ library provides no facilities for doing this. You would …

Member Avatar for vijayan121
0
156
Member Avatar for thenewbiecoder
Member Avatar for vijayan121
0
3K
Member Avatar for LopezGG

The header <vector> already defines [CODE]template< typename T, typename A > bool operator< ( const std::vector<T,A>& , const std::vector<T,A>& ) ; //performs a lexicographical comparison of the sequences (uses std::less<T>)[/CODE] and [CODE]template< typename T, typename A > bool operator== ( const std::vector<T,A>& , const std::vector<T,A>& ) ;[/CODE] So this would …

Member Avatar for LopezGG
0
165
Member Avatar for kgz

you could make approximate drawings using character based graphics. [code=cplusplus] #include<iostream> #include<string> #include <cassert> struct shape { virtual void draw() const = 0 ; virtual ~shape() {} }; struct rectangle : shape { explicit rectangle( int h = 10, int w = 10 ) : height(h), width(w) { assert( h>2 …

Member Avatar for Fuseteam
1
5K
Member Avatar for stereomatching

Use [B]std::result_of<>[/B] instead of [B]boost::result_of<>[/B] [CODE]#include <functional> struct S { double operator() ( char, int& ) [COLOR="Red"]const[/COLOR] ; [COLOR="Green"]// omitting const here is a (very) bad idea[/COLOR] }; int main() { return sizeof( std::result_of< S(char, int&) >::type ) == sizeof(double) ; }[/CODE] From Boost documentation: "If decltype is not enabled, …

Member Avatar for vijayan121
0
216
Member Avatar for carlpike

This is the typical producer-consumer scenario. [url]http://simpy.sourceforge.net/producer_consumer.htm[/url] The most efficient way would be to use a wait-free or lock-free fifo or ringbuffer. You could use one of Boost Lockfree [url]http://tim.klingt.org/boost_lockfree/[/url] (Recently voted into Boost, but not yet part of the distribution. Download from [url]http://tim.klingt.org/boost_lockfree.tar.gz[/url] Herb Sutter's implementation presented in DDJ …

Member Avatar for vijayan121
0
184
Member Avatar for stereomatching

[QUOTE=;][/QUOTE] > Is this kind of assignment well defined? yes; it is well-defined and well-behaved. Calls [b]release()[/b] on the auto_ptr.

Member Avatar for vijayan121
0
103
Member Avatar for stereomatching

Have a look at RapidXML, perhaps? Extremely good as long as DTD support is not required. [url]http://rapidxml.sourceforge.net/[/url] From the Boost Property Tree documentation: "The XML format is an industry standard for storing information in textual form. Unfortunately, there is no XML parser in Boost as of the time of this …

Member Avatar for stereomatching
0
348
Member Avatar for Zssffssz

> Seriously, what is the difference between calling time() on Unix vs Windows? Seriously? It depends. Entirely on the C library implementation that is being used. POSIX requires that [B]time()[/B] returns a 32-bit integral type holding the number of seconds elapsed since midnight (UTC) of January 1, 1970, not counting …

Member Avatar for vijayan121
0
884
Member Avatar for stereomatching

[B]std::future<>[/B] and [B]std::promise<>[/B] form a pair; together they provide an asynchronous inter-thread communication channel through which a value (or an exception) can be passed from one thread to another. [B]std::promise<>[/B] is used by the function which wants to set a value, which can then be retrieved by another thread through …

Member Avatar for stereomatching
0
548
Member Avatar for Wootens

> I'm trying to pass fout between functions. You cannot pass a stream object to a function by value - the copy constructor is private / deleted. Pass by reference instead: [ICODE]void my_function( std::ostream[COLOR="Red"]&[/COLOR] fout ) ;[/ICODE]

Member Avatar for vijayan121
0
160
Member Avatar for nerdygirl118

See [url]http://www.daniweb.com/software-development/cpp/threads/393577[/url] You can specify a hash function for [B]std::unordered_set[/B] in a similar way. For all of the words in a dictionary, the default hash function for [B]std::string[/B] would work quite well, though.

Member Avatar for vijayan121
0
201
Member Avatar for Muhammad Anas

Hint: Each element in [B]{3,5,7,9,11}[/B] is the corresponding element in [B]{2,4,6,8,10}[/B] plus one. Each element in [B]{6,10,14,18,22}[/B] is the corresponding element in [B]{3,5,7,9,11}[/B] multiplied by two.

Member Avatar for Muhammad Anas
0
3K
Member Avatar for trantran

The [B]volatile[/B] keyword was introduced at the time when C had no notion of concurrency other than time-slicing on a single processor. The notion of [B]volatile[/B] in C++ is the same as what it is in C. This article by Myers and Alexandrescu is instructive: [url]http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf[/url] This is what they …

Member Avatar for jmichae3
0
312
Member Avatar for karmstrong

[CODE]class telnumber { public: telnumber(); telnumber (string i_npa, string i_nxx, string i_line); [COLOR="Red"]virtual[/COLOR] ~telnumber(); [COLOR="Red"]// the destructor must be virtual[/COLOR] void setnpa (string newnpa); void setnxx (string newnxx); void setline (string newline); string getnpa(); string getnxx(); string getline(); [COLOR="Red"]// This must be defined or it should be declared as a …

Member Avatar for vijayan121
0
709
Member Avatar for MrEARTHSHAcKER
Member Avatar for existence19

First read up on what a good hash function should do, and choose a hash algorithm. [url]http://en.wikipedia.org/wiki/Hash_table#Hash_function[/url] Then implement the hash function keeping in mind what C++ requires of the hash function. For example, if you have opted for the UNIX 32-bit ELF hash, [CODE]#include <functional> #include <string> // C++ …

Member Avatar for vijayan121
0
823
Member Avatar for BoBok2002

>> Dragon: why don't you just call CreateProcess() in a loop and call it 10 times? Just listen to the Dragon, and treat everything else as white noise. This is almost certainly the problem you were asked to solve, but just fantasize for a moment that your program is to …

Member Avatar for vijayan121
0
3K
Member Avatar for sita12345

There is a problem with this code: [CODE] vector<x*>::iterator iter; for(iter=x.begin();iter!=x.end();++iter) { delete *iter; x.erase(iter); // once the element is erased, the iterator is no longer valid // ++iter now will cause undefined behaviour. }[/CODE] Instead, you could use the value returned by erase: [CODE] vector<x*>::iterator iter; for( iter=x.begin() ; …

Member Avatar for sita12345
0
367

The End.