1,247 Posted Topics

Member Avatar for svatstika

The trailing [B][I]const[/I][/B] on a non-static member function means that the abstract (logical, externally visible) state of the object pointed to by [B][I]this[/I][/B] will not be changed by this member function. Where possible, the compiler enforces this rule. However, the [B][I]const[/I][/B] specifier does not promise that the physical state ("raw …

Member Avatar for Ancient Dragon
0
264
Member Avatar for cwarn23

> The math problem is ((20+x) & 1234)=1000 as an example. The equality may have no solution. For [B](A+x) & B == C[/B], if any bit in [B]B[/B] is 0 while the same bit in [B]C[/B] is 1, there is no solution. ((20+x) & 1234)==1000 does not have a solution. …

Member Avatar for cwarn23
0
112
Member Avatar for samaniac

[QUOTE]Does any of you guys know where I can learn C++? What's the best website you know[/QUOTE] Perhaps you would want to consider learning to use C++ in the most effective way along with learning C++. Rather than join a whole generation of programmers who started to learn the most …

Member Avatar for vijayan121
0
242
Member Avatar for yongj

Unix tee is a filter which reads from stdin and in addition to piping the input to stdout also copies it into a file. In C++, we can generalize the idea to a reusable component. Create a user-defined ostream that can send its output to two output streams. tee is …

Member Avatar for yongj
0
1K
Member Avatar for Tellalca

The problem has nothing to do with either templates or destructors. This too will result in undefined behaviour: [CODE]int main() { int coordinates[3] ; delete[] coordinates ; // ??? } [/CODE]

Member Avatar for Tellalca
0
1K
Member Avatar for lochnessmonster

An example may help. [B]Code that does not use RAII:[/B] [CODE]struct M { M() ; // may throw! // ... }; struct A { A( const char* s, const char* path ) ; ~A() ; // required // ... private: char* cstr ; FILE* file ; M* ptr_m ; void …

Member Avatar for vijayan121
0
182
Member Avatar for stereomatching

> But I don't know how to declare a variable to save the value of *minIt [CODE]typename std::iterator_traits<iterator>::value_type saved_value = *minIt ;[/CODE] See: [url]http://www.sgi.com/tech/stl/iterator_traits.html[/url] Do you really need it? [CODE]template< typename iterator > void selection_sort( iterator begin, iterator end ) { if( begin != end ) { // find the …

Member Avatar for stereomatching
0
297
Member Avatar for merse

[QUOTE]I would like to know that my result is exact or not! It is possible somehow?[/QUOTE] See: [url]http://docs.sun.com/source/806-3568/ncg_goldberg.html[/url] Perhaps you should consider using a library; for example MPFR [url]http://www.mpfr.org/[/url]

Member Avatar for merse
0
237
Member Avatar for merse

[QUOTE]Only half! Why?[/QUOTE] That it is half is a clue, isn't it? Answer: rounding error Let [B]f1[/B] be a particular representable floating point number, and [B]f2[/B] be the next representable floating point number. If the IEEE-754 rounding method (round to nearest, ties to even) is used (as almost every current …

Member Avatar for vijayan121
0
233
Member Avatar for missil9

[CODE]#include <boost/regex.hpp> #include <string> #include <boost/lexical_cast.hpp> using namespace std; double scrape( const std::string& base, const std::string& match ) { boost::regex re(match); boost::smatch matches; [COLOR="Green"]// while( boost::regex_search( start, base.end(), matches, re ) )[/COLOR] [COLOR="Red"]if( boost::regex_search( base, matches, re ) )[/COLOR] { std::string value( matches[1].first, matches[1].second ); return boost::lexical_cast<double>(value) ; } else …

Member Avatar for missil9
0
267
Member Avatar for cmccaig

[QUOTE]Class basic_directory_iterator is an important component of the library. It provides an input iterator over the contents of a directory, with the value type being class basic_path. Typedefs directory_iterator and wdirectory_iterator are provided to cover the most common use cases. The following function, given a directory path and a file …

Member Avatar for Taywin
0
964
Member Avatar for MuniArt

> I can't get my display() method to work properly in the derived class. The function calls within it keep reading the dimensions from the original Rectangle class. Isn't there a way I can "virtualize" something and get the inner functions to read the right data? [code]class Rectangle //class declaration …

Member Avatar for innnocentdevil
0
472
Member Avatar for dspjm

We don't need to write [B]largerthan<>()[/B] when [B]std::greater<>()[/B] in [B]<functional>[/B] is available. We can also perform the [B]reduce()[/B] operation directly on the array; without using a temporary [B]list<>[/B] [CODE]#include <algorithm> #include <functional> template< typename T > std::size_t reduce( T ar[], std::size_t n ) { std::sort( ar, ar+n, std::greater<T>() ) ; …

Member Avatar for vijayan121
0
107
Member Avatar for Sohelp

There are no simple answers. [url]http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.3[/url] In my experience, a good function to inline is one i. which has a stable (unlikely to change) implementation. ii. which is frequently called (the program spends a signifanct portion of its time in calling and executing the function). iii. which has a code …

Member Avatar for Sohelp
0
250
Member Avatar for daviddoria

[CODE]template <class T> void WriteImage(typename T::Pointer image, std::string filename);[/CODE] As per the IS, a nested typename (for example, the typename Pointer nested in the typename T here) is non-deducible. [QUOTE]If a template parameter is used only in nondeduced contexts and is not explicitly specified, template argument deduction fails. The nondeduced …

Member Avatar for Fbody
0
4K
Member Avatar for nautolian

[CODE]#include <iostream> #include <fstream> #include <string> #include <iterator> #include <vector> #include <sstream> #include <algorithm> int main() { // read verbs from the file into a vector std::ifstream verbs_file( "verbs.txt" ) ; std::istream_iterator<std::string> begin(verbs_file), end ; std::vector<std::string> verb_seq( begin, end ) ; // get the sentence from stdin std::string sentence ; …

Member Avatar for nautolian
0
119
Member Avatar for burcin_erek

[QUOTE]e2 was wrong. 7.38.....[/QUOTE] Not really; it would be something like that. 7.389056... In [ICODE]1 + x/1! + x^2/2! + X^3/3! + ..... + x^n/n! + x^(n+1)/(n+1)! + .....[/ICODE], just as [ICODE]n! == (n-1)! * n[/ICODE], [ICODE]x^n == x^(n-1) * n[/ICODE]. We can eliminate the computation of [B]pow()[/B] for each …

Member Avatar for burcin erek
0
134
Member Avatar for merse

> Are there any library to solve this problem? There are many libraries: [url]http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic#Libraries[/url]

Member Avatar for merse
0
372
Member Avatar for frogboy77

[CODE] const slong limitsqr=2000; slong (*newarray)[limitsqr] = new slong[limitsqr][limitsqr] ; // delete with: delete[] newarray ; [/CODE]

Member Avatar for frogboy77
0
123
Member Avatar for Robbiedoes

Choosing a pseudo random-number generator involves a trade-off between the quality of the generator and its run-time performance. A variety of generators are available in Boost (and/or TR1). [url]http://www.boost.org/doc/libs/1_42_0/libs/random/random-generators.html[/url] [url]http://www.johndcook.com/cpp_TR1_random.html[/url]

Member Avatar for StuXYZ
0
205
Member Avatar for hl1202

You seem to be running out of memory; verify that [B]malloc()[/B]s return a non-NULL pointer.

Member Avatar for vijayan121
0
268
Member Avatar for heidik
Member Avatar for vijayan121
0
135
Member Avatar for xikkub

Change [ICODE]ofstream f("test.exe", ios::out | ios::binary); [/ICODE] To [ICODE]ofstream f("test.exe", [COLOR=Red]ios::in |[/COLOR] ios::out | ios::binary);[/ICODE] The first is equivalent to the C mode string [B]"wb"[/B], the second is equivalent to [B]"r+b"[/B] which is what you need here.

Member Avatar for xikkub
0
234
Member Avatar for rothn

And to fix the error, make this change: [ICODE]hFileMap = OpenFileMapping( [COLOR="Green"]/*PAGE_READONLY*/[/COLOR] [COLOR="Red"]FILE_MAP_READ[/COLOR], true, "animationMemFileClientOut"); [/ICODE]

Member Avatar for vijayan121
0
1K
Member Avatar for Hey11

> is there any function that gets the mode of an array without using pointers ? No. The array subscripting operator is a binary operator on a pointer and an integral value. [url]http://publib.boulder.ibm.com/infocenter/lnxpcomp/v7v91/index.jsp?topic=%2Fcom.ibm.vacpp7l.doc%2Flanguage%2Fref%2Fclrc05arsubex.htm[/url] If the distribution is unimodal and the array can be modified (sorted), a simple way to get …

Member Avatar for vijayan121
0
81
Member Avatar for cbsinc

If you have some familiarity with standard algorithms: [CODE] std::string str = " string \twith \n ws." ; str.erase( std::remove_copy_if( str.begin(), str.end(), str.begin(), ::isspace ), str.end() ) ; [/CODE]

Member Avatar for cbsinc
0
120
Member Avatar for Ninoaoe

[CODE]#include <string> #include <iostream> #include <sstream> int to_number( const std::string& word ) { std::istringstream stm(word) ; int n ; if( ( stm >> n ) && stm.eof() ) return n ; else throw 0 ; } int main() { std::string word ; int counter = 1 ; while( std::cout << …

Member Avatar for Ninoaoe
0
131
Member Avatar for Suzie999

[CODE]char exe_name[ MAX_PATH ] ; GetModuleFileNameA( GetModuleHandle(0), exe_name, MAX_PATH ) ;[/CODE] [url]http://msdn.microsoft.com/en-us/library/ms683197%28VS.85%29.aspx[/url]

Member Avatar for Suzie999
0
169
Member Avatar for vbx_wx

> Why it always introduces in front of the name,numbers? [B]std::type_info::name[/B] returns an implementation defined C-style string. For the compiler that you are using (GCC 3.x or above), you can demangle with [B]abi::__cxa_demangle()[/B] [CODE]#include <typeinfo> #include <string> #include <cxxabi.h> #include <stdexcept> #include <cstdlib> std::string demangled_name( const std::type_info& tinfo ) { …

Member Avatar for vijayan121
0
106
Member Avatar for tech9x

To just copy a file: [CODE]#include <fstream> bool copy_file( const char* infile, const char* outfile ) { std::ifstream fin( infile ) ; std::ofstream fout( outfile ) ; return fout << fin.rdbuf() ; }[/CODE]

Member Avatar for vijayan121
0
4K
Member Avatar for Orangeweapons

Tutorial: [url]http://curl.haxx.se/libcurl/c/libcurl-tutorial.html[/url] Example source file: [url]http://curl.haxx.se/libcurl/c/simple.html[/url]

Member Avatar for vijayan121
0
263
Member Avatar for heidik

Write comparison operators for [B]operator<[/B] and [B]operator==[/B] for the struct. eg. [CODE]struct A { int x, y, z ; inline bool operator< ( const A& that ) const ; inline bool operator== ( const A& that ) const { return (x==that.x) && (y==that.y) && (z==that.z) ; } }; bool A::operator< …

Member Avatar for heidik
0
847
Member Avatar for BarnacleBoy

[QUOTE]If your precision is 0.01 then this error is negligible so you don't really have to worry about it. Just limit the output to 2 decimals.[/QUOTE] Not quite. The result would depend on the magnitude of the number involved and the number of significant digits in the mantissa of the …

Member Avatar for vijayan121
0
216
Member Avatar for geekykitty

Use the stream manipulators [B]std::setw[/B] and [B]std::setfill[/B]. [url]http://www.cplusplus.com/reference/iostream/manipulators/setfill/[/url] [CODE=C++]#include <iostream> #include <iomanip> int main() { int hours = 6 ; int minutes = 2 ; std::cout << hours << ':' << std::setw(2) << std::setfill('0') << minutes << '\n' ; }[/CODE]

Member Avatar for Unimportant
0
97
Member Avatar for cmccaig

In [CODE]// ... int x = 8 ; int y = 9 ; auto foobar = [ &x, y ]( int a, int b ) { return x += a + b + y ; } // ...[/CODE] [ICODE][ &x, y ][/ICODE] specifies the identifiers declared outside the lambda function …

Member Avatar for cmccaig
0
96
Member Avatar for Steini_Ey

use [B]std::getline()[/B] [url]http://www.cppreference.com/wiki/string/getline[/url]

Member Avatar for Steini_Ey
0
4K
Member Avatar for wiseguy12851

> I would love to integrate assembly into my programs The assembly code that you would write is implementation dependent, and therefore non-portable.

Member Avatar for vijayan121
0
272
Member Avatar for ilkeamasya

Consider using a Patricia trie. [url]http://en.wikipedia.org/wiki/Radix_tree[/url] A C++ standard library compatible implementation: [url]http://code.google.com/p/patl/[/url]

Member Avatar for vijayan121
0
118
Member Avatar for Arthas

AFAIK, SDL event polling can't be done in a thread other than the thread that set the video mode. You could do something like this: The main thread (which set the video mode) polls for events and when an input event is received, it pushes it into (an appropriately synchronized) …

Member Avatar for Arthas
0
138
Member Avatar for Mr.Barca

> i want to put the number of the line for each item in the second column of the array You really need not store the line number separately; the row number of a two-dimensional array (or array-like structure) would become the implicit line number. [CODE]#include <iostream> #include <fstream> #include …

Member Avatar for Mr.Barca
0
121
Member Avatar for n.aggel

since a heap is a *balanced* binary tree (it has the 'shape' property), you do not need nodes to implement it. we can store the heap in a compact manner in a (dynamically resizeable) array; this would be much more efficient. see: [URL]http://en.wikipedia.org/wiki/Binary_heap#Heap_implementation[/URL]

Member Avatar for ani malviya
0
222
Member Avatar for kshaaban

Boost::uuid (C++) [url]http://www.boost.org/doc/libs/1_42_0/libs/uuid/index.html[/url] or the GUID struct (C) in <windows.h> [url]http://msdn.microsoft.com/en-us/library/aa373931%28VS.85%29.aspx[/url]

Member Avatar for kshaaban
0
221
Member Avatar for ziggystarman

[url]http://onlamp.com/pub/a/onlamp/2006/04/06/boostregex.html[/url] [url]http://www.drdobbs.com/184404797[/url] [url]http://www.informit.com/articles/article.aspx?p=517609[/url]

Member Avatar for ziggystarman
1
236
Member Avatar for nativeoak
Member Avatar for Greywolf333
0
146
Member Avatar for danalovesc

The value_type of a [icode]std::multimap<KEY,T>[/icode] is [icode]std::pair< [COLOR="Red"]const[/COLOR] KEY, T >[/icode]. So, [CODE]std::multimap<SortKey,T> firstMap; std::multimap<SearchKey, pair< const SortKey, T >* > secondMap; // ... std::multimap<SortKey,T>::iterator it = firstMap.insert( std::make_pair(key1,data) ) ; std::pair< [COLOR="Red"]const[/COLOR] SortKey, T >* mizi = &*it ; secondMap.insert( std::make_pair(key2,mizi) ) ; // ...[/CODE]

Member Avatar for mike_2000_17
0
1K
Member Avatar for patrick772goh

> it is not working. two reasons: a. [inlinecode]strcat(buffer,"\\root1\\root2\\test.dll") ;[/inlinecode] causes a buffer overflow b. [inlinecode]LoadLibrary((LPTSTR)buffer) ;[/inlinecode] casting is not the way to convert narrow char strings to wide char strings. [code=cplusplus]wchar_t wbuffer[ MAX_PATH ] ; wchar_t* result = _wgetcwd( wbuffer, MAX_PATH ) ; assert( result ) ; wcscat( wbuffer, …

Member Avatar for Mr.What
0
392
Member Avatar for Kanoisa

Don't [B]boost::filesystem::remove_all[/B] and [B]boost::filesystem::remove[/B] require a full path as the argument? AFAIK, lines 20 and 28 should have [ICODE]checkAndRemove( dir_iter->path(), BAD_TYPES )[/ICODE] instead of [ICODE]checkAndRemove( dir_iter->path().leaf(), BAD_TYPES )[/ICODE]

Member Avatar for Kanoisa
0
2K
Member Avatar for Arthas

Your build of the boost-thread library appears to be broken; built without MT support. MSVCRT and MSVCRTD are the single-threaded runtime libraries, you should not link to one of these libraries in any program that uses threads of any kind - native, Boost, POCO, ACE, wxWidgets, whatever. Either use Boost.Build …

Member Avatar for Stefano Mtangoo
0
485
Member Avatar for keeda

Either overload [B]operator<[/B] for node or write a binary predicate to compare nodes. eg. [code]struct compare_cost { bool operator() ( const node& a, const node& b ) const { return a.cost < b.cost ; } };[/code] If you just need a priority queue, just use [B]std::priority_queue<>[/B] [ICODE]std::priority_queue< node, std::deque<node>, compare_cost …

Member Avatar for vijayan121
0
149
Member Avatar for onako

[CODE]#include <typeinfo> template <typename MatTypeOne, typename MatTypeTwo> void funct(MatTypeOne& m1, MatTypeTwo& m2) { if( typeid(m1) == typeid(m2) ) { // objects m1 and m2 are of the same (run-time) type } } [/CODE]

Member Avatar for LordNemrod
0
113

The End.