1,247 Posted Topics
![]() | Re: > 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 … |
Re: > 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 … | |
Re: See: [url]http://forums.devx.com/showthread.php?t=171793[/url] | |
Re: See: [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12[/url] | |
Re: [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 … | |
Re: > 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( … | |
Re: > 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? … | |
Re: 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] | |
Re: 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] | |
Re: > 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 … | |
Re: 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]. | |
Re: [CODE]int i=0,a[length],j=0; [COLOR="Red"]// *** error: ISO C++ forbids variable length array 'a'[/COLOR][/CODE] | |
Re: 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. … | |
Re: 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 … | |
Re: 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 … | |
Re: It would be hard to beat the blitz::TinyVector for performance. [url]http://www.oonumerics.org/blitz/docs/blitz_7.html#SEC131[/url] | |
Re: > 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 … | |
Re: 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 … | |
Re: > 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 ) … | |
Re: 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 … | |
Re: 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], .... ) … | |
Re: the easiest way would be to use a library. eg. [url]http://www.sqlapi.com/[/url] | |
Re: > 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: … | |
Re: [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 … | |
Re: [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 … | |
Re: > 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 … | |
Re: Your program is running out of memory. See: [url]http://www.cplusplus.com/reference/std/new/bad_alloc/[/url] | |
Re: > 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 */ } … | |
![]() | Re: > 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 … ![]() |
Re: > 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 … | |
![]() | Re: 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* … |
Re: See [url]http://curl.haxx.se/docs/faq.html#Link_errors_when_building_libcur[/url] | |
Re: [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] | |
Re: 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] | |
Re: 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] … | |
Re: 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] | |
Re: > 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] | |
Re: > 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. | |
Re: > 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. | |
Re: [CODE]//while(!str_number.eof()) // { // str_number >> str_description; // ... while( str_number >> str_description ) // while attempt to extract a string has succeeded { ... [/CODE] | |
Re: [CODE]void [COLOR="Red"]Manufacturer::[/COLOR]WhatIsYourTeam() { // ... } [/CODE] | |
Re: [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 … | |
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
Re: [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. … | |
Re: > 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 … | |
Re: 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, … | |
![]() | Re: 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. ![]() |
Re: [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 … |
The End.