1,247 Posted Topics

Member Avatar for Burn August Red

> hours worked is 70, so the output should read 1 week, 3 days, 6 hours. > this is assuming the work week is 40 hours with 8 hour days. [B]70 / 40 == 1[/B] (integer division) [B]70 % 40 == 30[/B] (modulus) [url]http://www.vias.org/cppcourse/chap04_01.html[/url] [B]30 / 8 == 3[/B] [B]30 …

Member Avatar for WaltP
0
209
Member Avatar for Labdabeta

> I am just wondering if this is necessary or if I can write the functions in normal c++ as well. No, it isn't necessary. As always, you would need to build both the library and the program using the library with the same compiler (version). > Oh, also what …

Member Avatar for vijayan121
0
133
Member Avatar for inspek
Member Avatar for inspek
0
173
Member Avatar for Cross213

See: [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12[/url]

Member Avatar for Cross213
0
152
Member Avatar for stereomatching

[B]> At first, I wrote something like this[/B] [code] template<typename T, size_t size> inline size_t const sizeof_array(T const [size]){return size;} [/code] [B]> but if failed...Why version one fail?[/B] The reason is extremely simple: 1. These three are different ways of declaring the same function - one which takes a single …

Member Avatar for vijayan121
0
181
Member Avatar for trantran

> Does anyone has a brilliant (and simple!) way to selectively control access > by giving different rights to different friends? I don't have anything brilliant, but using access helpers to provide selective access is reasonably simple. [CODE]class A { void foo() {} void bar() {} // grant void foo_not_bar( …

Member Avatar for mike_2000_17
0
160
Member Avatar for Sunshine2011

> Normally you wouldn't use a function to create a vector anyway, > since returning it (and thus causing it to be copied) is not efficient. Not really. [B]Dave Abrahams in 'Want Speed? Pass by Value.'[/B] - [url]http://cpp-next.com/archive/2009/08/want-speed-pass-by-value[/url] explains why: Be honest: how does the following code make you feel? …

Member Avatar for vijayan121
0
158
Member Avatar for Zssffssz

Oh yeah will this work in ofstream? Yes. [B]std::ofstream[/B] is a [B]std::ostream[/B]. C++11: Just use raw string literals. [CODE]std::cout << R"---(The path is "C:\Equation_MinGW\bin\g++.exe". (C++11))---" << '\n' ; std::cout << R"(menu ---- 1. one 2. two 3. three )" ; [/CODE] See: [url]http://www2.research.att.com/~bs/C++0xFAQ.html#raw-strings[/url]

Member Avatar for vijayan121
0
107
Member Avatar for NoUserNameHere

Once you have fixed the constructor ([B]test<int>[/B] => [B]test<T>[/B]), fix the template friend declaration. See: [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.16[/url]

Member Avatar for vijayan121
0
73
Member Avatar for dospy

> why they needed to make 2 types of strings, char string and w_char string? A few years down the line, they realized that two types of strings are nowhere near enough; so now we have five. [CODE] std::string str = "hello world\n" ; // string where char_type is char …

Member Avatar for dospy
0
271
Member Avatar for L0s3r

If we call [B]rand5()[/B] seven times and add up the results, we would get an integer in the inclusive interval [B][7,35][/B]. Divide this number by [B]5.0[/B] and we would get a real number in the inclusive interval [B][1.0,7.0][/B]. Take care of the round-off correctly (how?) and you have [B]rand7()[/B].

Member Avatar for StuXYZ
0
166
Member Avatar for suraj_p

[CODE]int i=0,a[length],j=0; [COLOR="Red"]// *** error: ISO C++ forbids variable length array 'a'[/COLOR][/CODE]

Member Avatar for vijayan121
0
172
Member Avatar for eblanco1

Something like this: [CODE] const std::string SINGLE = "Single" ; const std::string MARRIED = "Married" ; const std::string INVALID = "??????" ; if( marital_status == 1 ) std::cout << SINGLE ; else if( marital_status == 2 ) std::cout << MARRIED ; else cout << INVALID ;[/CODE] Alternatively, use a switch-case. …

Member Avatar for eblanco1
0
170
Member Avatar for SCass2010

Since [B]std::multimap<>[/B] stores the keys in an ordered manner, [CODE]#include <map> template< typename K, typename T, typename C, typename A > typename std::multimap<K,T,C,A>::size_type num_unique_keys( const std::multimap<K,T,C,A>& mmap ) { if( mmap.size() < 2U ) return mmap.size() ; const C& cmp = mmap.key_comp() ; typename std::multimap<K,T,C,A>::size_type n = 1 ; auto …

Member Avatar for vijayan121
0
1K
Member Avatar for dospy

I would suggest that you study the fundamental concepts involved in concurrent programming. Understanding that is the harder and the important part. Learning to use thread facilities provided by a particular platform or library is the easy part; it gives you the tools, but you need to know when and …

Member Avatar for dospy
0
251
Member Avatar for mike_2000_17

It would be hard to beat the blitz::TinyVector for performance. [url]http://www.oonumerics.org/blitz/docs/blitz_7.html#SEC131[/url]

Member Avatar for mike_2000_17
0
530
Member Avatar for stereomatching

> I can't see why "double-checked locking" would cause race condition? See: [url]http://drdobbs.com/cpp/184405726[/url] This conclusion was true (for C++03) at the time the article was written. [QUOTE]Nothing you do can alter the fundamental problem: You need to be able to specify a constraint on instruction ordering, and your language gives …

Member Avatar for stereomatching
0
182
Member Avatar for tajendra

Well, the DLL code will have complete access to the address space of the process. Access to external resources (files etc) can be restricted by loading it into a sandbox. Get an impersonation token with limited access rights/privileges [url]http://msdn.microsoft.com/en-us/library/aa378184.aspx[/url] In a thread of your process, impersonate the user with limited …

Member Avatar for vijayan121
0
154
Member Avatar for dospy

> there are 2 common ways to loop through a vector Perhaps four. [CODE]#include <vector> #include <algorithm> void one( std::vector<int>& seq ) { for( auto& i : seq ) ++i ; } void two( std::vector<int>& seq ) { for( auto iter = seq.begin() ; iter != seq.end() ; ++iter ) …

Member Avatar for dospy
0
182
Member Avatar for marirs07

You don't need anything more than the [B]offsetof[/B] macro in [B]<cstdddef>[/B] [CODE]#include <cstddef> #include <iostream> struct A { int a ; int b ; char c ; // ... }; void foo( int* p ) // address of A::b { A* pa = reinterpret_cast<A*>( reinterpret_cast<char*>(p) - offsetof(A,b) ) ; std::cout …

Member Avatar for marirs07
0
3K
Member Avatar for johans22

You need to create a 'copy on write' view. Open the file for read access: [icode]CreateFile( ...., GENERIC_READ, .... ) ;[/icode] Create the FileMapping for read access: [icode]CreateFileMapping( ....., PAGE_READONLY, ..... ) ;[/icode] Create a copy-on-write view: [icode]MapViewOfFile( ......, [b]FILE_MAP_COPY[/b], ..... ) ;[/icode] Unix: [icode]mmap( ...., PROT_READ|PROT_WRITE, [b]MAP_PRIVATE[/b], .... ) …

Member Avatar for johans22
0
82
Member Avatar for sofia24

the easiest way would be to use a library. eg. [url]http://www.sqlapi.com/[/url]

Member Avatar for Stefano Mtangoo
0
1K
Member Avatar for Demetrio.pepi

> I am trying to compile this example [url]http://www.boost.org/doc/libs/[/url][COLOR="Red"]1_42_0[/COLOR]/... > and I am getting the error "/usr/local/boost_[COLOR="Red"]1_47_0[/COLOR]/... There is a version mismatch. The code for 1.47.0 would be: [CODE]BOOST_FOREACH( const std::string& name, m_modules ) { // pt.[COLOR="Red"]put[/COLOR]( "debug.modules.module", name, true ) ; pt.[COLOR="Red"]add[/COLOR]( "debug.modules.module", name, true ) ; }[/CODE] See: …

Member Avatar for Demetrio.pepi
0
392
Member Avatar for Jared1337

[icode]char thousands[] = {"", "M", "MM", "MMM", "MMMM"};[/icode] This is an error; thousands is an array of chars, not an array of c-style strings. You need to do something like this instead. [icode]const char* thousands[] = {"", "M", "MM", "MMM", "MMMM"};[/icode] > i have one error, which is C2110: cannot …

Member Avatar for raptr_dflo
0
4K
Member Avatar for NathanOliver

[code=c++] #include <sstream> #include <exception> class ConversionException: public std::exception { virtual const char* what() const throw() { return "Bad Conversion"; } } convertError; template<typename To, typename From> const To Convert(const From & convertFrom) { To convertTo; std::stringstream ss; ss << convertFrom; if(ss >> convertTo) return convertTo; throw convertError; } int …

Member Avatar for mike_2000_17
0
161
Member Avatar for guccimane

> I used getline to read the first line and to check for spaces By default, formatted input ignores whitespaces. [icode] input >> nextChar ; // nextChar contains the next non-whitespace char[/icode] So, [code]#include <fstream> #include <cctype> // good if there are digits at the beginning and end of file …

Member Avatar for vijayan121
0
279
Member Avatar for jh3lps

Your program is running out of memory. See: [url]http://www.cplusplus.com/reference/std/new/bad_alloc/[/url]

Member Avatar for raptr_dflo
0
783
Member Avatar for owenransen

> Do I need to be careful? If you decide to be careful, the code would be something like: [CODE] wchar_t wc = L'A' ; char c = 'A' ; const auto& ctype = std::use_facet< std::ctype<wchar_t> >( std::locale() ) ; if( ctype.widen(c) == wc ) { /* whatever */ } …

Member Avatar for owenransen
0
3K
Member Avatar for nalasimbha

> there was no .tli file. Why is this? The [B].tli[/B] contains generated inline member functions that wrap the interface methods. No [B].tli[/B] file is generated id you suppressed it's generation by using the [B]raw_interfaces_only[/B] attribute in the [B]#import[/B] directive. > When I was trying to instantiate the COM object …

Member Avatar for nalasimbha
0
745
Member Avatar for MrAppleseed

> I'm having issues with processing the tokens that I've made. Make the task easier by using [B]std::string[/B]. [CODE]#include <iostream> #include <string> #include <sstream> int main() { std::string line ; while( std::cout << '>' && std::getline( std::cin, line ) ) { // tokenize the line on white space std::string token …

Member Avatar for Narue
0
134
Member Avatar for nblackburn

Assuming that shell32.dll exports a function with that signature with the entry point at ordinal 262, a. Load shell32.dll into the process address space. b. Get the address of the function at ordinal 262 c. Call the function. Something like: [CODE]#include <windows.h> int main() { CoInitialize(0) ; { const char* …

Member Avatar for vijayan121
0
350
Member Avatar for IndianaRonaldo

See [url]http://curl.haxx.se/docs/faq.html#Link_errors_when_building_libcur[/url]

Member Avatar for vijayan121
0
330
Member Avatar for goluman

[CODE]#include <vector> #include <utility> int main() { // C++0X std::vector< std::pair<int,int> > sequence = { {1,2}, {3,4}, {5,6}, {7,8} } ; int sum2nd = 0 ; for( const auto& pair : sequence ) sum2nd += pair.second ; }[/CODE]

Member Avatar for Narue
0
179
Member Avatar for cppdeveloper

Use std::vector<> instead of raw arrays. For a beginner, a vector is easier to use (correctly). [url]http://www.cprogramming.com/tutorial/stl/vector.html[/url]

Member Avatar for raptr_dflo
0
164
Member Avatar for googlygoo

The std namespace has a [ICODE]std::max[/ICODE]. This is causing a name clash because of [CODE]using namespace std ; int max ;[/CODE] (The implementation seems to be gratuitously including a header which declares [ICODE]std::max[/ICODE]). Either remove the using directive (and qualify names with [ICODE]std::[/ICODE] as in [ICODE]std::cout[/ICODE])or change the name [ICODE]max[/ICODE] …

Member Avatar for vijayan121
0
427
Member Avatar for trishtren

Clang; a great C++98 compiler, available as a set of libraries, under an open source non-viral license. However, it does not yet support most of the C++11 features. [url]http://clang.llvm.org/features.html#libraryarch[/url]

Member Avatar for vijayan121
0
94
Member Avatar for dophine

> Just out of curiosity, you allocate the entire image in a single block of memory... You might want t have a look at the boost pool library. [url]http://www.boost.org/doc/libs/1_47_0/libs/pool/doc/index.html[/url]

Member Avatar for dophine
0
270
Member Avatar for ChaseRLewis

> conversion from 'std::streamsize' to 'size_t', possible loss of data Unless you are using files larger than 4GB in size on a 32-bit platform, you can safely ignore this warning.

Member Avatar for vijayan121
0
226
Member Avatar for harryhaaren

> its only when the vector get reallocated in memory (due to another thread loading a different sample into it) The memory buffer held by the vector could get reallocated. You need to synchronize access to the vector across multiple threads.

Member Avatar for harryhaaren
0
655
Member Avatar for ksm092

[CODE]//while(!str_number.eof()) // { // str_number >> str_description; // ... while( str_number >> str_description ) // while attempt to extract a string has succeeded { ... [/CODE]

Member Avatar for nuclear
0
1K
Member Avatar for SCass2010

[CODE]void [COLOR="Red"]Manufacturer::[/COLOR]WhatIsYourTeam() { // ... } [/CODE]

Member Avatar for NathanOliver
0
138
Member Avatar for maxcraft

[CODE]// ... for (i=0; i<10; i++) { if (nums[i]== k) { temp=1; pos=i; } } if (temp==1) cout << "first occurrence : " << pos << " "; else cout << "first occurrence : " << "-1" << " ";[/CODE] This fragment finds the [B]last[/B] occurrence if any. To locate …

Member Avatar for vijayan121
0
115
Member Avatar for Chilton

Pete Becker's 'The C++ Standard Library Extensions: A Tutorial and Reference' has been available for some time. [url]http://www.amazon.com/Standard-Library-Extensions-Tutorial-Reference/dp/0321412990/ref=sr_1_1?s=books&ie=UTF8&qid=1313201008&sr=1-1[/url] 'C++ Concurrency in Action' by Anthony Williams has in-depth coverage of concurrency features in C++11. [url]http://www.manning.com/williams/[/url] Scott Meyers' presentation materials on C++11 is also a useful resource. [url]http://www.artima.com/shop/overview_of_the_new_cpp[/url] InformIT has a series …

Member Avatar for Chilton
0
215
Member Avatar for Stefano Mtangoo

In the boost distribution: [ICODE]<directoy_where_boost_has_been_unpacked>/boost_1_47_0/doc/html[/ICODE] PDF documentation can be downloaded from sourceforge: [url]http://sourceforge.net/projects/boost/files/boost-docs/1.47.0/[/url] Or use wget. Something like: [B]> wget --mirror -p --no-parent --convert-links -P ./boostdoc [url]http://www.boost.org/doc/libs/1_47_0/libs/libraries.htm[/url][/B] Note: 1_47_0 is boost version 1.47.0. Use 1_46_1 for 1.46.1 and so on.

Member Avatar for vijayan121
0
853
Member Avatar for yazooney

Dev-C++ on windows uses the Mingw port of GCC by default. MinGW uses native Windows DLLs for everything; code compiled with MinGW will use standard Microsoft runtime libraries such as MSVCRT.DLL. Dev-C++ can also be used in combination with Cygwin and this is what you need to do if you …

Member Avatar for chevuru.anil
0
2K
Member Avatar for paperstars

[ICODE]factorial *= (i-1) * i[/ICODE] would make the entire factorial zero (or very close to zero) when i == 1. One way out of this is to start with i == 3. In each term of the expansion, the numerator can be computed by multiplying the previous term by x*x. …

Member Avatar for paperstars
0
2K
Member Avatar for shadowscape

> Point taken, but realize that I'm no Windows programmer > so that format was, to me, associated with product keys. uuids are not a Windows innovation; they conform to the standard originally specified by OSF/DCE and now in ISO/IEC 11578:1996. Windows uses uuids; but so do several other systems …

Member Avatar for L7Sqr
0
1K
Member Avatar for henrimontreal

A more general version of NathanOliver's idea; somewhat academic, and using the boost iterator library. [CODE]#include <iterator> #include <type_traits> #include <locale> #include <functional> #include <boost/iterator/filter_iterator.hpp> #include <boost/iterator/transform_iterator.hpp> #include <algorithm> #include <string> #include <iostream> #include <list> namespace { template < typename ITERATOR, typename FILTER, typename TRANSFORM > bool _is_palindorome( ITERATOR begin, …

Member Avatar for vijayan121
0
126
Member Avatar for yoni0505

If you are going to perform unformatted I/O, open the stream in binary mode (use std::ios_base::binary). Or else, text mode escape sequence translations will take place.

Member Avatar for yoni0505
0
207
Member Avatar for Saith

[CODE][B]>[/B] int number; [B]>[/B] stm >> number; [B]>[/B] while( stm.fail() ) ....[/CODE] This kind of construct fails to check for crud remaining in the input; [B]567#$![/B] would be treated as a valid number with a value of 567. If the attempt to read a non-ws char after reading the number …

Member Avatar for vijayan121
0
336

The End.