1,247 Posted Topics
Re: 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]". | |
Re: You need to add [B]Sally.cpp[/B] to the project. Menu: Project->Add Files ... IIRC. | |
Re: [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() … | |
Re: 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' … | |
Re: > 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* … | |
Re: > 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 … | |
Re: 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 … | |
Re: > 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 … | |
Re: > 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, … | |
Re: 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] | |
Re: > 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 … | |
Re: > 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. … | |
Re: > 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 ) {} … | |
Re: > 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 … | |
Re: `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() - … | |
Re: 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] | |
Re: 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.) | |
| |
Re: [QUOTE=;][/QUOTE] See: [url]http://www.beej.us/guide/bgnet/[/url] | |
Re: [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 … | |
Re: > 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 … | |
Re: > 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 … | |
Re: [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] | |
Re: > 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 … | |
Re: > 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 … | |
Re: 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 … | |
Re: > 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( … | |
Re: > ... 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 … | |
Re: 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] | |
Re: 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( … | |
Re: > 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 … | |
Re: See: [url]http://en.wikipedia.org/wiki/Least_common_multiple#Applications[/url] | |
Re: 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 … | |
Re: 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 … | |
Re: 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, … | |
![]() | Re: 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 … |
Re: [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. | |
Re: 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 … | |
Re: > 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 … | |
Re: [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 … | |
Re: > 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] | |
Re: 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. | |
Re: 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. | |
Re: 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 … ![]() | |
Re: [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 … | |
Re: > is there any way to do something like that? The short answer is: No. | |
Re: 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++ … | |
Re: >> 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 … | |
Re: 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() ; … |
The End.