- Strength to Increase Rep
- +16
- Strength to Decrease Rep
- -4
- Upvotes Received
- 388
- Posts with Upvotes
- 336
- Upvoting Members
- 156
- Downvotes Received
- 13
- Posts with Downvotes
- 10
- Downvoting Members
- 7
Re: try posing your query in a directx forum. eg.[url]http://www.gamedev.net/community/forums/forum.asp?forum_id=10[/url] | |
Re: the standard c++ library exposes only one name [ICODE]std[/ICODE] to the global namespace. everything else is put inside the namespace [ICODE]std[/ICODE]. change [ICODE]#include <iostream.h>[/ICODE] to [CODE]#include <iostream> using namespace std ;[/CODE] without the using directive, you need to qualify names with [ICODE]std::[/ICODE] ie. [ICODE]std::cout[/ICODE] etc. | |
Re: you could also use the algorithm [ICODE]std::unique_copy[/ICODE]. [code=c++]#include <iostream> #include <fstream> #include <vector> #include <iterator> #include <algorithm> struct consecutive_blanks { bool operator() ( char first, char next ) const { return first==' ' && next==' ' ; } }; int main() { std::ifstream fin( "text_1.txt" ) ; fin >> std::noskipws … | |
Re: Toggle a boolean flag, perhaps? const int arr[3][3] = { { 23, 54, 76 }, { 37, 19, 28 }, { 62, 13, 19 }, } ; bool alt = true ; for( const auto& row : arr ) for( int i : row ) { if(alt) std::cout << i … | |
Re: #include <iostream> #include <locale> #include <iomanip> // http://en.cppreference.com/w/cpp/locale/numpunct struct space_separated : std::numpunct<char> { // http://en.cppreference.com/w/cpp/locale/numpunct/thousands_sep virtual char do_thousands_sep() const override { return ' ' ; } // separate with spaces // http://en.cppreference.com/w/cpp/locale/numpunct/grouping virtual std::string do_grouping() const override { return "\3"; } // in groups of 3 digits }; int main() … | |
Re: here are some references: [url]http://en.wikipedia.org/wiki/Performance_analysis[/url] [url]http://perfsuite.ncsa.uiuc.edu/[/url] [url]http://en.wikipedia.org/wiki/Valgrind[/url] [url]http://www.gnu.org/software/binutils/manual/gprof-2.9.1/html_mono/gprof.html[/url] | |
Re: Use a Threadpool Cleanup Group to manage graceful shutdown. [url]http://msdn.microsoft.com/En-US/library/ms682036%28v=VS.85%29.aspx[/url] | |
Re: the basic problem here is that we need to select one item at random when we do not know beforehand how many items there are. the most common example of this in real code is when a random element has to be picked from a list (size unknown). there is … | |
Re: here is something obtained thru googling (i've no clue about either dev-c++ or sdl); see if these help. [url]http://www.gpwiki.org/index.php/C:How_to_set_up_your_SDL_Build_Environment#Windows:_Dev-C.2B.2B[/url] [url]http://www.imrtechnology.ngemu.com/sdldevtut.htm[/url] if they do not, abandon daniweb and try a forum where there may be people who are more knowledgable. eg. [url]http://gpwiki.org/forums/viewforum.php?f=2[/url] | |
Re: [quote]I don't want others to edit my strings. It appears there's no easy solution for this, as I don't want any internet connection or such methods[/quote] Here's one (stand alone, without network etc.) way to do it; this might help to get you started. It assumes that all you are … | |
Re: 15. Use const proactively. Summary const is your friend. Immutable values are easier to understand, track, and reason about, so prefer constants over variables wherever it is sensible and make const your default choice when you define a value. It's safe, it's checked at compile time, and it's integrated with … | |
Re: std::ofstream is not a *CopyConstructible* or *CopyAssignable* type. But it is MoveConstructible and MoveAssignable. The CopyConstructor is explicitly deleted. http://en.cppreference.com/w/cpp/io/basic_ofstream/basic_ofstream The CopyAssignment operator is implicitly deleted. http://en.cppreference.com/w/cpp/io/basic_ofstream/operator%3D The CopyAssignment operator of `routecaseBasedCDRFile` wold have been implicitly deleted if had not been declared. In this case, there is a user-defined CopyAssignment … | |
Re: Trustworthy (and succinct) recommendations: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list https://isocpp.org/get-started 'What is the best book to learn C++ from?' in https://isocpp.org/wiki/faq/how-to-learn-cpp | |
Re: Use an *enumeration* http://en.cppreference.com/w/cpp/language/enum Something like: #include <iostream> #include <string> enum class choice_t : std::size_t { one = 1, two = 2 /* ... */, invalid = std::size_t(-1) }; std::ostream& operator << ( std::ostream& stm, choice_t c ) { std::cout << "choice_t::" ; static const std::string text[] = { "invalid", … | |
Re: This is an infinite loop: `for( int i = 0, n = 2; ; ++i ) { /* ... (no break statement) */ }` A missing condition makes the implied while clause equivalent to `while(true)`. At some point of time, when `i` becomes equal to `std::numeric_limits<int>::max()`, `++i` will cause a … | |
Re: Use *thread storage duration* for the singleton. http://en.cppreference.com/w/cpp/language/storage_duration struct A // per-thread singleton { static A& instance() ; private: A() { /* ... */ }; A( const A& ) = delete ; // non-copyable A( A&& ) = delete ; // non-moveable }; A& A::instance() // Meyer's singleton { thread_local … | |
Re: The keys in the map are const objects: `const std::string`; they can't be modified directly inside the map. Something like this, perhaps: #include <iostream> #include <map> #include <string> #include <cctype> std::string to_lower( const std::string& str ) { std::string lc ; for( char c : str ) lc += std::tolower(c) ; … | |
Re: Don't know about Turbo C++. This is standard C++; it may work in Turbo C++ too. // open the source file for input (text) std::ifstream srce_file( "G:/one/file.txt" ) ; // or "G:\\one\\file.txt" if it is a really old version of Windows // check for is_open() elided for brevity // open … | |
Re: `<cerrno>` defines several standard integer error codes (*integer constant expressions* with type `int`). For instance, ENOENT for 'No such file or directory' http://en.cppreference.com/w/cpp/error/errno_macros `<system_error>` gives us the *scoped enum* `std::errc` For instance, `std::errc::no_such_file_or_directory` http://en.cppreference.com/w/cpp/error/errc `<system_error>` also has the class `std::error_code`. Objects of this type can be created from an *error … | |
Re: `ScheduleFile mySchedule();` This is the declaration of a nullary function returning a *prvalue* of type `ScheduleFile` See: https://en.wikipedia.org/wiki/Most_vexing_parse int main() { // ScheduleFile mySchedule(); // declare a function ScheduleFile mySchedule ; // define a default initialised object } | |
Re: The canonical C++ way is to use templated callbacks in conjunction with: wrapping the call in a polymorphic call wrapper `std::function<>` and currying with `std::bind()` http://en.cppreference.com/w/cpp/utility/functional/function http://en.cppreference.com/w/cpp/utility/functional/bind Sample code: http://coliru.stacked-crooked.com/a/8d4283e68de561cf http://rextester.com/VBNT79084 | |
Re: #include <iostream> #include <limits> #include <stdexcept> #include <algorithm> #include <cassert> // algorithm from 'Hacker's Delight' by Henry S. Warren // http://www.amazon.com/dp/0201914654 unsigned int plus( unsigned int a, unsigned int b ) { auto carry = a & b; auto sum = a ^ b; while( carry != 0 ) { … | |
Re: To search for a pattern in a string, use the C++ regular expression library. Tutorial: https://solarianprogrammer.com/2011/10/12/cpp-11-regex-tutorial/ http://www.informit.com/articles/article.aspx?p=2079020 The simplest way to run code asynchronously, and retrieve the result of the asynchronous operation, is to use `std::async()`. Tutorial: https://solarianprogrammer.com/2012/10/17/cpp-11-async-tutorial/ http://www.drdobbs.com/cpp/c11s-async-template/240001196 Once you have read up on these two, writing the code … | |
Re: > compile error : no matching member function for call to 'insert' There is no error in the posted code (once the missing headers are added). Since C++11, `insert()` and `erase()` on standard constainers accept `const_iterators`. http://en.cppreference.com/w/cpp/container/vector/insert http://en.cppreference.com/w/cpp/container/vector/erase Note: this does not break legacy code. The IS requires that for … | |
Re: An external merge sort using four files, perhaps? [url]http://en.wikipedia.org/wiki/Merge_sort#Use_with_tape_drives[/url] | |
Re: > ...probably some gcc/g++ extension that was messing things up > (which is obviously the only real possibility here). it is not some gcc/g++ extension; it is POSIX [ICODE]man pause[/ICODE] [url]http://node1.yo-linux.com/cgi-bin/man2html?cgi_command=pause(2[/url]) | |
Re: Book: The C++ Standard Library: A Tutorial and Reference (2nd Edition) by Josuttis http://www.amazon.com/Standard-Library-Tutorial-Reference-2nd/dp/0321623215 Online reference: http://en.cppreference.com/w/ Offline archive: http://en.cppreference.com/w/File:html_book_20141118.zip | |
Re: GNU specific, and worth studying merely for the elegance of the design. (Note: it violates ODR, but the implementation is allowed to provide well-defined semantics for undefined behaviour.) **<begion quote>** The following goals directed the design of the libstdc++ debug mode: Correctness: <...> Performance: <...> Usability: <...> **Minimize recompilation**: While … | |
Re: > is it used to substitute constructor? Yes. An exception-safe and (usually) more efficient substitute. > This function is typically used to replace the construction `std::shared_ptr<T>(new T(args...))` of a shared pointer from the raw pointer returned by a call to new. > In contrast to that expression, `std::make_shared<T>` typically allocates … | |
Re: #include <iostream> int main() { int x ; std::cin >> x ; // if input fails, x would be set to zero int y = 0 ; std::cin >> y ; // do nothing if std::cin is in a failed state // there is no need to check that x … |