question_id
int64
25
74.7M
answer_id
int64
332
74.7M
title
stringlengths
20
150
question
stringlengths
23
4.1k
answer
stringlengths
20
4.1k
6,393,689
6,394,074
sample XSD fails with "error: no declaration found for element X"
In spite of being a total newbie in the xml parsing arena, I was able to xsd to create valid c++ and compile and link successfully, but the compiler optimized(?) away the instantiation. So, starting at step one, I try the hello world xml example at CodeSynthesis. But that fails: [wally@lenovotower xml]$ make hello xs...
Personally I find the combination of Python and lxml to be pretty invaluable. Your XML document and the corresponding XML schema work just fine: from lxml import etree xsddoc = etree.parse('hello.xsd') xsd = etree.XMLSchema(xsddoc) xml_parser = etree.XMLParser(schema=xsd) xmldoc = etree.parse('hello.xml', parser=xml_...
6,393,776
6,393,843
What is the difference between a macro and a const in C++?
I was asked this question in a technical interview: What is the difference between a const and a macro in C++? My answer was that a macro is a preprocessor directive and it could be difficult to debug the application if you use a macro since it is replaced with the constant expression before compilation, whereas a co...
Macros and constants are not remotely the same thing, each is sometimes appropriate for the circumstances, and your answer only scratches at the surface of the difference. Also, C++ has two different kinds of constants. A constant defined with the const qualifier is best thought of as an unmodifiable variable. It has...
6,393,806
6,479,643
C++ Segmentation Fault Only External to Eclipse
I have developed a C++ application in Eclipse. When run outside of Eclipse, it takes a segmentation fault after a consistent number (4) of user actions. It did not seem like anything special at first. I thought I would just use Eclipse to debug through the application and find the bug. However, when I run the applicati...
At the recommendation of Node (see comments on original question, I ran my app through Valgrind. After cleaning up memory management issues identified by Valgrind, my problem is gone. Thank you!
6,394,039
6,394,050
c++ what is a good debugger for segmentation errors?
Does anyone know a good debugger for C++ segmentation errors on the Linux environment? It would be good enough if the debugger could trace which function is causing the error.
GDB! what else is available on Linux? Check this out for starting up with GDB, its a nice, concise and easy to understand tutorial.
6,394,337
6,394,548
How do I get the RECT of title bar's window controls (maximize, minimize, close buttons) ? I tried to make a custom color title bar
I am trying to intercept the WM_NCPAINT message by first calling ::DefWindowProc, then paint over it. However, when I paint the window controls of the title bar or non-client area, I need to have its RECT structure. Therefore, how do I access the REcT structure?
The update region is passed in message's wParam. The non client area of the window isn't rectangular so you don't get a single RECT. I presume you are aware that WM_ NCPAINT is not compatible with Vista DWM glass.
6,394,465
6,394,552
Accepting certain types in constructor
as a follow up to this question, how can the code be changed so that i can use it in the constructor of a class? im writing a new class where the input needs to be an number of some kind, but nothing else. the code, however, is like declaring the type in front of a function. since constructors dont exactly have types, ...
I think you want to restrict types for constructor template. If so, then you can do this: #include <type_traits> //#include <tr1/type_traits> // for C++03, use std::tr1:: class C { public: template<typename T> C(T value, typename enable_if<std::is_arithmetic<T>::value,T>::type *p=0) { } }; Thi...
6,394,654
6,394,658
C++ - defenition - private inheritance
Possible Duplicate: Private/protected inheritance Can you give me example for private inheritance in C++? As I understood, in this sort of inheritance, the public and the protected features of the parent don't filter throght the child, and only the public features of the child are visible.
Private Inheritance: All Public members of the Base Class become Private Members of the Derived class & All Protected members of the Base Class become Private Members of the Derived Class. An code Example: Class Base { public: int a; protected: int b; private: int c; }; class Derived:pr...
6,394,783
6,394,823
hash table/ unordered map in C++
I am looking for a template for hash map that i can rely on, and use whenever i need hash table. I was trying to use hash_map but found out that it is deprecated now.Tried using unordered_map, but i get the following error- error: #error This file requires compiler and library support for the upcoming ISO C++ s ...
hash_map (or rather, unordered_map, as it was called to avoid name collisions) is in the latest version of C++ (c++0x, or c++11) but many compilers, including yours, supported it before that. Your compiler is just being nice and stopping you from writing potentially non-portable code without your explicit consent. As ...
6,394,862
6,394,931
c++ app can't receive consecutive messages from c# app
My problem is that when I do TcpClient con = new TcpClient ("127.0.0.1", 5432); NetworkStream str = con.GetStream (); Annoucement msg = new Annoucement (); msg.typ = Annoucement.msgType.NOWY_GRACZ; Serializer.SerializeWithLengthPrefix (str, msg, PrefixStyle.Base128); Ser...
From the reference: Sets *data to point directly at the unread part of the CodedInputStream's underlying buffer, and *size to the size of that buffer, but does not advance the stream's current position. This will always either produce a non-empty buffer or return false. If the caller consumes any of this d...
6,394,959
6,395,104
boost::interprocess -- std::string vs. std::vector
I used boost::interprocess::managed_(windows_)shared_memory::construct to construct an interprocess vector holding an own class, which has a member variable of type std::string and another of type std::vector, so: class myclass { public: myclass() { } std::string _mystring; ...
std::string works because your standard library implementation uses small-string-optimization (SSO). That means that the value of the string "something" is copied into the string object itself, without any dynamic memory allocations. Hence you can read it from the other process. For longer strings (try 30 characters) i...
6,395,483
6,395,502
C++ Type Conversion Operator and Memory Leak
I want to allow my Class1 to be convertible to Class2 by a type conversion operator: class Class1 { public: operator Class2() const { //.... } } But if I create a Class2 object in the operator implementation, very likely it will not get deleted by the caller. So what is the best way to implement su...
There only needs to be deletion if you do something crazy like this: operator Class2() const { Class2 *p = new Class2(); ... return *p; } However, the following is fine: operator Class2() const { Class2 c2; ... return c2; }
6,395,642
6,395,699
Help in interpreting a c++ method
I have the following c++ method: typedef unsigned long p3tOffsetType; p3tOffsetType buildString(std::string string) { for (stringMap::const_iterator string_iterator = strings.begin(); string_iterator != strings.end(); ++string_iterator) { if (string_iterator->second == string) return string_...
Assuming that strings is a map<p3tOffsetType, std::string> and that string_offset is initialized to zero, it seems to do the following: Imagine that you call the method a few times with, say, "Hello", "Hi", and "Hey", and that you would treat all these strings as C-strings and store them in the same char array. The arr...
6,395,658
6,395,679
what happens to unused memory in C++
I was going through some practice coding problems , and i came across one - Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node. EXAMPLE: Input: the node ‘c’ from the linked list a->b->c->d->e Result: nothing is returned, but the new linked list l...
In Java, the memory could eventually be freed by the garbage collector. There is no guarantee of when (and therefore, if) that happens. (In practice, it will usually happen very quickly). In C++ with smart pointers, the deallocation of memory is guaranteed as soon as the object cannot be addressed anymore. In effect, i...
6,395,768
6,395,811
A method using different flavors of it's own private members
class A{ private: std::vector<class X> flavor1 std::vector<class X> flavor2 public: void useVectorOfX(std::vector<class X> someflavor){ ... // same logic for both flavors } } Now I want to call useVectorOfX() from another class, giving it either flavor1 or flavor2 depending on need. I can think ...
What about way 1 in a more descriptive format: class A { public: enum { flavor1 = 0, // used as array index, first element must be zero flavor2, } vector_flavor; static const int number_of_flavors = 2; void useVectorOfX(vector_flavor flav){ std::vector<class X> someflavor& =...
6,396,038
6,396,534
OpenGL: no light for a simple glut cube
OpenGL: no light for a simple glut cube Hi, i'm trying to study lights in opengl and glut but I have problems quite early. I have this code for making a lighted cube in a custom position with custom camera setting: void testApp::draw(){     static float amb[] =  {0.4, 0.4, 0.4, 0.0};     static float dif[] =  {1.0, 1.0...
You are really far away from your cube. Make it smaller and move it closer. Alternatively, change your lighting like this: float light_diffuse[] = {100.0, 0.0, 100.0, 100.0}; float light_position[] = {-100.0, 100.0, 1.0, 0.0}; You will hardly see any light effects on a cube. Consider using a teapot.
6,396,055
6,396,098
Declare by including its header, not by explicit declaration
What does this piece of advice mean? It's from The C++ Programming Language, Special Edition. Declare standard library facilities by including its header, not by explicit declaration; §16.1.2. Here's an extract from §16.1.2 that I believe is relevant: For a standard library facility to be used its header must be ...
It means do this: #include <cstdio> Not this: int printf(const char * format, ...); You will often find people suggesting that doing the latter will lead to quicker compilation times (as the compiler won't have to read and interpret all the standard header files).
6,396,330
6,396,345
Why should I use c_str() in functions
I am reading the book C++ Primer and at the file input output chapter it uses: ifstream infile(ifile.c_str()); to open a file whose name is in the string ifile. I tried the code and it works perfectly even without c_str(). So what is the point of using it? Should I use c_str() when I am trying to open a file from a co...
The constructor for ifstream used to only take a const char * (which is what the c_str() method provides. I believe that there is a new constructor for it that takes a std::string in the upcoming standard, (edit) see this answer. It could also be specific to your implementation.
6,396,469
6,571,862
directory_iterator - make a copy to "rewind"?
So I wrote a small program to try out Boost Filesystem. My program will write how many files there is in the current path and then the file names. Here's my program: #include <iostream> #include <boost/filesystem.hpp> using namespace boost::filesystem; int main(){ directory_iterator start = directory_iterator(cur...
It is the same issue. The directory iterator is a one pass iterator. You cannot save a copy and go a second pass. Each time you increment the iterator you get the next entry, but you cannot decrement it and you cannot go back and start over, not even if you have saved a copy of the starting point. If you want to traver...
6,396,474
6,396,521
How can i get clear -export function names from built DLL? I always get originalname+gibberish
note: First of all i am using visual studio 2010. Usually i need dll with some exported functions that i need to use from outside apps.. Normally this is how my dll header looks... #define DLLAPI extern "C" __declspec(dllexport) DLLAPI BOOL WINAPI FUNCTION1(...); DLLAPI BOOL WINAPI FUNCTION2(...); I don't add any com...
Just create the DEF file as you've shown above with just your two functions and go into the link options and specify to use this def file. From http://msdn.microsoft.com/en-us/library/34c30xs1%28v=vs.80%29.aspx The /DEF option passes a module-definition file (.def) to the linker. Only one .def file can be specif...
6,396,542
6,397,210
Create dmp files in release build
how can I create dmp files when a program crash in release build? I think I should trigger the exceptions but I don't know how
On Windows you can use the Debug Helper API to write a minidump file to any location you choose. This file does not need to be sent to Microsoft. http://msdn.microsoft.com/en-us/library/ms680369(v=vs.85).aspx As others have mentioned, the dump file will be useless without PDB files from the correct build. You may wan...
6,396,599
6,396,628
Is a dynamic cast appropriate here?
Say in a game, we have Entities that communicate with each other. Say a player collides with an Item and now, that item should be placed in his std::vector<Item*> When the player receives the collision message, he receives the item as an Entity*. Would it then be appropriate for the player to cast it as an item, and if...
dynamic_cast helps you check the validity while performing downcasting. It returns a NULL or throws an exception(std::bad_cast for References)if the pointer or the reference cannot be safely downcasted. It is unclear to say unless you show us the class structures.
6,396,625
6,396,652
Pointer or class as iterator?
I'm writing a random access container in C++. In my code I use this (well, in my real code I use all kinds of Allocator typedefs, this is just easier to understand): template<typename T, typename Allocator = std::allocator<T> > class Carray { public: // ... typedef T* iterator; typedef const T* const_iterat...
You have iterator category, difference type etc avalaibale for you even if you have a raw pointer. You see, there is this iterator_traits<> template which you should use. It is already specialized for pointers. iterator_traits<int*>::value_type // ... etc. //or iterator traits<my_custom_iterator>::value_type
6,396,649
6,396,685
Confused with fstream and pointers
I would like to write a function which takes an fstream, processes it, and fills information in a struct I supply in the second argument. My problem is that I am confused how to use pointers and fstreams as I get debug errors: Access violation writing location 0xcccccccc. Here is the main function: int main() { ...
You forgot to take the address of your fields: fin.read(( char* ) &kfstruct.num_views, sizeof( int ) ); ^^^ [As an aside, note that it's better from a maintenance point of view to do sizeof(kfstruct.num_views). So if the type ever changes, your code will still work.]
6,396,702
6,396,732
Why does bind(..) for ipv6 under mac os x give me error number 47
I am taking first steps in socket programming as an added complexity I am trying to use ipv6: Shouldn't this: struct sockaddr_in6* addr = new sockaddr_in6; int s = socket(AF_INET6, SOCK_STREAM, 0); addr->sin6_addr = in6addr_any; addr->sin6_port = 1234; int ret = bind(s, (struct sockaddr*)addr, sizeof(struct sockaddr_in...
You should set addr->sin6_family to AF_INET6 or at least zero-initialise the address structure before passing it to bind().
6,396,756
6,396,779
Does const'ing primitive types in function parameters result in a significant performance boost?
A friend told me that it's more efficient to do int addNumbers(const int number1, const int number2); than int addNumbers(int number1, int number2); assuming of course that number1 and number2 won't be assigned new values. Does this result in a significant performance boost? Are there any other side effects I should ...
const correctness is more of letting compiler help you guard against making honest mistakes. Declaring the const-ness of a parameter is just another form of type safety rather than a boost for performance. Most of the modern compiler will be able to detect if a variable is really constant or not, and apply correct o...
6,396,767
6,396,832
How to query for system features/properties?
I want to write a program which is capable of printing out system properties. Is this possible? If so, with C/C++, how can one learn system features/properties? For example, the following properties: hardware : Memory 3.8 gib ubuntu : release 10.10 ( maveric ) system status: available disk space 51.1 gib use...
In Linux You can simple use the function: int uname(struct utsname *buf); by including the header #include <sys/utsname.h> it returns the system information as a part of the structure: struct utsname { char sysname[]; /* Operating system name (e.g., "Linux") */ char nodename[]; /* Name within "...
6,397,092
6,397,107
Does boost::bind() copy parameters by reference or by value?
Why does valgrind's DRD tool complaines "Conflicting load by thread ... at size 4": about such code: void SomeFunction(const int& value) { boost::bind(..., value); /* <-- complaines on this line with last backtrace function "new(int)" */ } Does boost::bind() stores values by referen...
By value. 1 But you can make it copy by ref instead: void SomeFunction(const int& value) { boost::bind(..., boost::ref(value)); boost::bind(..., boost::cref(value)); // by const ref } 1 http://www.boost.org/doc/libs/1_46_1/libs/bind/bind.html#Purpose a copy of the value of i is stored into the function objec...
6,397,129
6,397,197
Choosing and using an IDE
I've been using Visual Studio 2010 for C++ development for a while but I'd like to move to an open source option. I'm considering using Eclipse C++. Are there any problems with it that I should know about? Also, I want to develop GUI applications. Presumably Eclipse allows this but I can't find any documentation on it ...
I was about to close this as a duplicate shopping question, but the GUI part is what stopped me. You have two very good options: Qt Creator: integrated version control, debugger support and Qt GUI editor. Code::Blocks: integrated debugger, some plugins and a wxWidgets GUI editor.
6,397,223
6,397,242
Derive from template argument and call its copy constructor
Please consider the following code: template<class basic_ios_type> class basic_ios_adaptor; template<template<typename, class> class basic_ios_type, typename char_type, class traits_type> class basic_ios_adaptor<basic_ios_type<char_type, traits_type>> : public basic_ios_type<char_type, traits_type> { public: t...
You can't copy streams, because their copy constructor is private (or more specifically, the copy ctor from basic_ios). See also this question.
6,397,278
6,397,333
passing heavy objects C++0x
I have a function which produces a type of expensive object (containing vectors and a maps of a non fixed size) so I really want to avoid invoking copy c'tors. Until now I have just returned a std::shared_ptr from the method and used that but I think it is ugly and requires typedeffing to be really usuable. I am aware ...
If you don't like reading ,here is a link to a video about rvalues and move-semantics: http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-9-of-n
6,397,288
6,397,699
.lib sub-dependencies
I'm creating a small .lib This small .lib needs some other .lib. I would like for my small .lib to contain the "code" of these other .lib. Then the application which will use my small .lib won't need these other .lib. I'm using Visual C++ 2010.
I'll assume you put all the projects in one solution. Right-click the "small lib" project, Properties, Librarian, General. Add the dependent libraries to the Additional Dependencies setting. To make sure you get the debug build of them in your Debug configuration and the release build in your Release configuration, ...
6,397,330
6,397,351
Defining static const variables of a template class
I have a vector class which has some static const variables like ZERO. Now since vector is often implemented as a template class (and mine is no exception), I see a lot of this code: template<> const Vector2<float> Vector2<float>::ZERO; template<> const Vector2<float> Vector2<float>::UNIT_X(1, 0); //... and so on, and ...
No, that's perfectly legitimate and totally Standard. If you want to use a static variable in a templated class, there's no way you could possibly define all possible instantiations of it- those types may not even be nameable and therefore specializable. Hence, it's very necessary that template classes can have static ...
6,397,356
6,397,386
What does the virtual keyword mean when overriding a method?
What does the keyword virtual do when overriding a method? I'm not using it and everything works fine. Does every compiler behave the same in this regard? Should I use it or not?
You cannot override a member function without it. You can only hide one. struct Base { void foo() {} }; struct Derived : Base { void foo() {} }; Derived::foo does not override Base::foo; it simply hides it because it has the same name, such that the following: Derived d; d.foo(); invokes Derived::foo. virtual ...
6,397,501
6,418,957
how to compile ASL (boost based Adobe C++ gui library) on windows 7?
So I am triing to compile ASL on windows 7. I got Adobe C++ Library files, docs and examples from here to %ASL% I have downloaded and compiled boost (in some other folder %boost%) So now I have compiled Boost (all libs), bjam, VS 2008 installed (I have it in %ProgramFiles(x86)%) Now I try to run %ASL%/tools/build.ba...
I was unable to build asl using .bat script shipped with library, but direct using of bjam did the job. download and install boost libraries (version 1.45), intel tbb libraries (last version), apl and asl (last versions) compile or download pre-compilled bjam and put it on %PATH% unpack downloaded libraries to disk u...
6,397,545
6,397,565
_Block_Type_Is_Valid (pHead->nBlockUse) Error
I been working in a new project but I encounter with a problem which I can't see why fail. When I perfom this line delete textY give me the error _Block_Type_Is_Valid (pHead->nBlockUse). So what am I doing wrong? This is the source code: Text.h #ifndef TEXT_H #define TEXT_H typedef boost::shared_ptr<Font> FontPtr; ...
Just use a std::string. That error means that you double deleted something, or something like that, a problem that you wouldn't have if you didn't manage your own memory. Your code is littered with memory leaks and other bugs that you won't have with std::string.
6,397,657
6,397,680
Instantiating multiple templates
If I have a class called Tuple<T, SIZE> and I want, let's say, 20 different float templates instantiated when compiling the library (so that the user does not encounter linking errors): template Tuple<float, 1>; template Tuple<float, 2>; ... template Tuple<float, 20>; Is there any way to recursively perform the above?...
I'm sorry you are out of luck. Unless you use a preprocessor metaprogramming library (boost.pp), there is no way to automate that. Not with template metaprogramming. What you have produced there are implicit instantiations of Tuple<float, N>. But implicit instantiations have two important differences to explicit instan...
6,397,734
6,397,741
Is there a standard construct for 'choose<bool,typename,typename>'?
I sometimes find myself in need for the following: template<bool B, typename T1, typename T2> struct choose{ typedef T1 type; }; template<typename T1, typename T2> struct choose<false, T1, T2>{ typedef T2 type; }; I use this to conditionally choose one type or the other. Now, is there already something in the sta...
Yes: it is called std::conditional in C++0x (or boost::conditional in Boost). The boost::mpl::if that you cite has a corresponding boost::mpl::if_c that takes a bool instead of a type; this is a common pattern in the Boost type traits libraries.
6,397,775
6,397,810
C++ & Java - overloading operator
I have a difficult to understand the subject of overloading operator in C++ and Java. For example, I define a new class Fraction: class Fraction { public: Fraction (int top, int bottom) { t = top; b = bottom; } int numerator() { return t; } int denominator() { return b; } private: int t, b; }; a...
For C++: Overloading the << Operator on msdn // overload_date.cpp // compile with: /EHsc #include <iostream> using namespace std; class Date { int mo, da, yr; public: Date(int m, int d, int y) { mo = m; da = d; yr = y; } friend ostream& operator<<(ostream& os, const Date& dt); }; ostream& ...
6,397,827
6,398,156
Different ways of suming specific numbers to gain 100
I want to write a code to show how many ways one can sum up 5 different numbers to get 100. For example, the numbers are 2,5,10,20,50, and they can be repeated any number of times. Here 50+50 is one way and 20+20+20+20+20. I have no idea how to program this. I think it should be done by a recursive function, and I've t...
Just for fun #include <iostream> #include <vector> #include <iterator> #include <numeric> #include <algorithm> static const int terms[] = { 2,5,10,20,50, /*end marker*/0 }; using namespace std; typedef vector <int> Solution; typedef vector <Solution> Solutions; inline int Sum(const Solution& s) { return accu...
6,397,865
6,397,956
Crashing Console application, at the end of a loop. Looking for advice. (pic inside)
(C++ CLR based project) The picture below shows the debugging process. Basically the program is designed to draw a simple ASCII level for a game. (30 x 30, and on each iteration of the loop draw a character (either a 'space' or a '+')) http://imageshack.us/photo/my-images/52/prgramcrash.jpg/ The x is the width, y is t...
The problem here is that you're defining your drawEngine to have a width and height of 80: class DrawEngine { public: DrawEngine (int xSize = 80, int ySize = 50); ... }; Yet when you create a level, you're saying the level should be size 30x30: bool Game::run(void) { level = new Level(&drawArea, 30, ...
6,398,002
6,398,135
help needed with parsing binary file
I am trying to interact with an open-source program by writing a C++ application what can read-modify-write a binary file format used by that program. The good thing is that the program is open source, the bad thing is that its binary files are not following any "standard", just its own way of reading and saving. So th...
m_position x = -1.07374e+008 If you look with the debugger's raw memory view at the value you'll see that the byte values of the float is 0xcccccccc. That's a special value, the MSVC compiler uses it to initialize variables in the Debug build. In other words, your m_position variable never got assigned. Lacking more...
6,398,090
6,398,144
Is it possible to Invoke an exported "private" method in c++
Is it possible to invoke a private method of a class exported from a DLL? Will it be hidden from people who would like to use it but are not supposed to? thanks :)
Yes, it's possible, but you need to use dirty casting tricks or rely on semi-undefined behaviour, but for certainty you can call an exported function, no matter it's private/public status. The language does not provide security against malicious attackers. It will help everyone play by the rules, but it will not guard ...
6,398,152
6,398,165
Why does IntelliSense show a constructor I didn't write?
What does it mean by the suggestion give by the IDE? (using VS 2010) There is no constructor of baseClass_2 which takes the suggested parameter(const baseClass_2 &). So, why this is showing up?
Implicitly defined copy constructor. There are special member functions which get defined by default when you not explicitly declare / define them: Default constructor Copy constructor Destructor Note that the default constructor will not get defined when you provide any other constructor besides the copy constructor...
6,398,174
6,398,215
C++ Sorting huge binary files
I need to sort huge binary files that won't fit into memory. It's no option to use a sort algorithm and continuously read/write from I/O device. Is there any possibility to use something like a memory mapped file?
This is a solved problem, as explained on this wiki page: http://en.wikipedia.org/wiki/External_sorting Basically, read in some set amount, sort it, save into a file, and repeat. Then, read in a smaller amount from each file, sort these, and continue until done. UPDATE: You may want to look at the java code he uses, i...
6,398,229
6,398,245
Why is the Console Closing after I've included cin.get()?
I've just started learning C++ using C++ Primer Plus but I'm having trouble with one of the examples. Like the book instructed I included cin.get() at the end to prevent the console from closing by itself. However, in this instance it still closes by itself unless I add two cin.get() statements which I don't understand...
cin >> carrots; This line leaves a trailing newline token in the input stream, which then gets consumed by the next cin.get(). Just do a simple cin.ignore() directly before that: cin.ignore(); cin.get();
6,398,278
6,398,650
TR1 regex: capture groups?
I am using TR1 Regular Expressions (for VS2010) and what I'm trying to do is search for specific pattern for a group called "name", and another pattern for a group called "value". I think what I want is called a capture group, but I'm not sure if that's the right terminology. I want to assign matches to the pattern "[^...
The C++ TR1 and C++11 regular expression grammars don't support named capture groups. You'll have to do unnamed capture groups. Also, make sure you don't run into escaping issues. You'll have to escape some characters twice: one for being in a C++ string, and another for being in a regex. The pattern (([^:\r\n]+):\s\s(...
6,398,358
6,398,404
What is BOOST_FILESYSTEM_VERSION 3 analog for BOOST_FILESYSTEM_VERSION 2 path.native_file_string()?
So I try to port my old project (from boost 1.44 to 1.61) I found out that there is no path.native_file_string() in boost::filesystem v3... So what is analog for path.native_file_string() in boost::filesystem v3? (I do not want to use v2 any more but I need such functionality as native_file_string)
If you are talking about path::external_file_string (there is no native_file_string in Boost.FileSystem v2 currently), the equivalent is path::native. This returns a string in the host OS's format, using a string type that is native for that system (std::wstring for Windows, std::string for Linux, etc).
6,398,430
6,398,500
boost::thread and std::unique_ptr
Is it somehow possible to pass an std::unique_ptr as a parameter to a boost::thread constructor? If not, what is the best workaround? A small example: // errors: g++ uniqueptr_thread.cpp -std=c++0x #include <iostream> #include <memory> #include <boost/thread.hpp> class TestThread{ public: void operator()(std::uniqu...
This compiles and runs for me: #include <iostream> #include <memory> #include <thread> class TestThread{ public: void operator()(std::unique_ptr<int> val){ std::cout << "parameter: " << *val << std::endl; } }; int main() { std::unique_ptr<int> ptr(new int(5)); std::thread th( TestThread(), std::move(ptr...
6,398,460
6,398,486
C++ less verbose alternative to passing container.start() and container.end()
I declare a vector<Bla> blaVec and write a function: template<typename Iterator> void doSomething(Iterator first, Iterator last) { ... } Then I call this function on blaVec with: doSomething(blaVec.begin(), blaVec.end()); However, I really would like something shorter like doSomething(blaVec) but without having to sp...
If you find that verbose, then you can wrap that with this: template<typename Container> void doSomething(Container &c) { doSomething(c.begin(), c.end()); //internally call the iterator version. } And use this function, instead of iterator version. Also, you can use iterator version, when you don't want the functi...
6,398,618
6,398,638
Is it possible to get pixelcolor(x,y) from covered(non active) window?
Is this possible even? I am searching around the net but can't find a thing.
Most windows will handle WM_PRINTCLIENT, which can be used to create a bitmap of the client area even when the window is not visible.
6,398,817
6,445,013
Problem linking Boost.Filesystem statically to a shared library
I'm building a shared library with GCC 4.5.2 and Boost 1.46.1 (compiled with --build-type=complete) and this is a command from Makefile which does the linkage part: $(CXX) -static -lboost_filesystem -fpic -shared $^ -o $@ Everything compiles fine but I get the following error when it gets loaded by application: plugin...
I believe that: Your use of -static and -shared is not the right way. The only more-or-less reliable way to control linking would be: -Wl,-Bstatic -lboost_filesystem -Wl,-Bshared at the end of the command line. You fail to link to boost_system. The failure happens because you seem to actually link to the static vers...
6,398,864
6,398,942
need help to getin ifstream::open to open a file and getline from it
I am just trying to open this file and use the getline function to read from the file but I cant seem to figure out why it is not working. I have stepped through it many times and the fileOpen variable is being loaded correctly with the file im trying to open, so Im unsure on why it wont open, to use getline with it. I...
The path::filename function returns the base filename. If you have a path of "foo\bar.txt", path::filename will return "bar.txt". So unless "foo\" is in the current directory, the file probably doesn't exist. What you're more likely looking for is this: file.open(dirIter->path().native()); Or, you can use the boost::f...
6,398,902
6,400,874
Best way to implement LRU cache
I was looking at this problem of LRU cache implementation where after the size of the cache is full, the least recently used item is popped out and it is replaced by the new item. I have two implementations in mind: 1). Create two maps which looks something like this std::map<timestamp, k> time_to_key std::map<key, std...
If you want an LRU cache, the simplest in Java is LinkedHashMap. The default behaviour is FIFO however you can changes it to "access order" which makes it an LRU cache. public static <K,V> Map<K,V> lruCache(final int maxSize) { return new LinkedHashMap<K, V>(maxSize*4/3, 0.75f, true) { @Override pro...
6,398,912
6,398,983
Template parameters not used in partial specialization
I have the following code: template<typename T, typename Allocator = std::allocator<T> > class Carray { // ... typedef T* pointer; typedef pointer iterator; // ... }; Now I'm trying to do partial specialization for iterator_traits. It seems OK to me, but g++ 4.4.5 complains: #include <iterator> namesp...
You shouldn't need a specialization at all here: iterator_traits is already specialized for pointer types and if you do end up with an iterator that is a class type, you can just define those required typedefs in the iterator class. The problem is that in order to match the primary specialization, the compiler needs t...
6,398,990
6,399,001
overloaded << insertion operator isn't working correctly
So I can't figure out why my insertion operator isn't working for my list class. I've looked at it for a while and I think the syntax is correct for overloading. Not sure on this one. Any hints as to why it's not working?? Here's the code: EDIT:Changed some code around to what it currently is right now. Sorry, the pro...
poly is a pointer, to use your custom operator << you need to say cout << *poly; // output the object pointed-to, not the pointer itself You haven't overloaded what it means to insert a Polynomial*. Nor should you try. Besides that, you probably should accept the object by const reference, there's no reason for a str...
6,399,081
6,399,409
how to define an enumeration inside a class and use it from the outside
Just because I don't know exactly where to look this up in my c++ book, or on google. How do I actually define some enumerations(in this case { left=1, right=2, top=3, bottom=4 }) inside a class. I want to be able to pass this enumeration as a parameter to member functions instead of an integer, therefore using the enu...
The simplest change needed to get your code to work is this: class mySprite : public sf::Sprite { public: enum side{ left=1, right=2, top=3, bottom=4 }; float GetSide(side aSide) { switch(aSide) { // do stuff // add breaks; as appropriate case left: ...
6,399,090
6,399,098
C++ convert vector<int> to vector<double>
What is a good clean way to convert a std::vector<int> intVec to std::vector<double> doubleVec. Or, more generally, to convert two vectors of convertible types?
Use std::vector's range constructor: std::vector<int> intVec; std::vector<double> doubleVec(intVec.begin(), intVec.end());
6,399,186
6,399,236
How do I most effectively prevent my normally-distributed random variable from being zero?
I'm writing a Monte Carlo algorithm, in which at one point I need to divide by a random variable. More precisely: the random variable is used as a step width for a difference quotient, so I actually first multiply something by the variable and then again divide it out of some locally linear function of this expression....
your way seems elegant enough, maybe a little different: do { h = r(); } while (h == 0.0);
6,399,286
6,399,385
<<operator is only printing an empty line
In main the list prints out using the insertion operator, but all that I get is an empty line. Not sure why. Is it that there is nothing being stored in the list even when you use the set_coefficient? Any other critiquing is welcome. Thanks here's the driver: #include <iostream> #include "polynomial.h" using namespace...
if(c != 0 && start == 0) start = new PolyNode(c,d,0); else if(c!= 0 && start != 0) start->coefficient = c; else if(c == 0){ cout << "deleting a term" << endl; delete start; } if (c != 0 && start == 0) // this situation may occur ? you have already judged surrounding if ...
6,399,493
6,399,512
What is CLI/C++ exactly? How does it differ from 'normal' c++?
Let me clarify what I mean by 'normal' C++ first- I'm currently reading Walter Savitch's "Problem Solving in C++". As far as I am aware this is not written specifically for Microsoft or Unix. So my question is, how does what I am learning in this book (which I am using for my universal knowledge-gaining of c++) differ ...
C++/CLI, (Also sometimes C++/CLR) refers to a language which is positioned somewhere in between native C++, and the .NET framework. It's usually used for applications where you need to bridge some native code (pure C++) and managed code (Like VB, C#, F#, etc). C++/CLI is a much different beast than regular C++ though....
6,399,500
6,399,528
create global dynamic array inside the function
I am writing a programm in C++. In my programm I need to create an array with dynamic size inside one function, but this array should be also accessable for other functions. I will not post here my code, just write one dummy example. char *array; void function_1() { array = new char(3); array[0] = "value 1"; ...
First, of course it will exist outside, that's all what dynamic allocation is about. Also, the variable itself is global. Also, it should be a char const** array; and the allocation should be new char const*[3] (note the square brackets). The const because you won't change the contents of the strings here. Second, don'...
6,399,542
6,399,607
Printing Stringstream Outputs Pointer
Rather than outputting the expected string of "Bar", the following code outputs what looks to be a pointer. #include <sstream> #include <iostream> int main() { std::stringstream Foo("Bar"); std::cout << Foo << std::endl; // Outputs "0x22fe80." return 0; } This can be worked around by using Foo.str(), but ...
This can be worked around by using Foo.str(), but it's caused some issues for me in the past. What causes this strange behavior? Where is it documented? It's not strange at all. A stream is a stream, not a string. You can obtain the [string] buffer with the member function .str(). That's not a workaround: it's the AP...
6,399,769
6,399,904
In method / function overloading, must every version be reimplemented?
I want to implement double dispatch. Say I have a class like so: class Entity { public: virtual void eventHandler(Message* msg, Entity* entity); } Then eventually I create derived entities. Say I eventually create several different types which derive from Entity. Do I need to forward declare them all in Entity.h...
In double-dispatch you have two class hierarchies, A and B. A has a bunch of overloaded methods that take different versions of B and B has a single method that takes A. Each of these methods need one argument. You need to declare all different versions in the A base class and implement all of them in A derived classe...
6,399,770
6,399,819
Can anyone explain this output to me?
So I was playing around with some thought experiments where I imagined what would happen when two functions became mutually recursive. One such one was what if both functions could potentially fall into an infinite loop. To that end, I thought up of this simple example: #include <iostream> #include <cstdlib> int foo(i...
Since you didn't specify which C++ you're on about I'll give the C++0x answer: This is in fact undefined behaviour in C++0x. I can't fully explain the behaviour if you're using C++03, but since your stack will eventually overflow, you're still really within the realm of implementation-dependent behaviour. Expecting any...
6,399,779
6,399,803
Deleting DirectShow Filters (Destructor not called)
I have built a custom DirectShow filter that implements CSource such as class Myfilter : public CSource { ~MyFilter(){ delete everything;} } When I use this filter in GraphStudio, I can delete it properly, the destructor is called correctly. When I create my filter via COM instaciation, I can no longer delete it wi...
You're not supposed to delete COM objects, you should Release() them. CSource probably implements IUnknown::Release() as delete this, when the reference count drops to 0.
6,399,804
6,462,109
Automatic static invocation of derived types
Does anyone know of a way to make derived classes automatically instantiate a static variable with a template type (this either has to require nothing from the writer of the derived class, or force him to call this static method in order to make the derived class definition valid). This is probably impossible to unders...
If anyone is still interested, I figured it out. Static template member variables are not automatically instantiated unless they are used. I needed it to be instantiated before the constructor was called, so I couldn't make it a static local. The solution is to make it a static template member variable, and then use it...
6,399,822
6,399,990
Reading a text file - fopen vs. ifstream
Googling file input I found two ways to input text from a file - fopen and ifstream. Below are the two snippets. I have a text file consisting of one line with an integer I need to read in. Should I use fopen or ifstream? SNIPPET 1 - FOPEN FILE * pFile = fopen ("myfile.txt" , "r"); char mystring [100]; if (pFile == ...
I would prefer ifstream because it is a bit more modular than fopen. Suppose you want the code that reads from the stream to also read from a string stream, or from any other istream. You could write it like this: void file_reader() { string line; ifstream myfile ("example.txt"); if (myfile.is_open()) ...
6,399,854
6,399,878
Turning bits into values
How does a computer know that (int x, y) x << y means shift over y bits? I don't mean the shift part. I mean the y part. Does the computer shift x by one and subtract one from y until y == 0? If not how does the computer figures out the value of y? If say y = 10, then the binary representation is 0b1010. The computer...
you're saying you have 2 bit arrays and you're trying to create a shift operator for them? the easiest way to do it would probably be to convert the right one, y, into an integer and then shift every bit in x by that amount.....otherwise if you want to operate on it 1 bit at at time it'll be even less efficient. you'll...
6,399,898
6,399,998
Is the typedef-name optional in a typedef declaration?
I was quite surprised when I saw the following code compile without errors or warnings in g++-4.2: typedef enum test { one }; My assumption was that if you used the typedef keyword it would require an extra identifier as in: typedef enum test { one } test; As already mentioned, g++-4.2 accepts it without even a warni...
It is a degenerate syntax that is allowed but provides no benefit. Most modern compilers can be provoked into emitting a warning about it; by default, they may not. Without the typedef name, the keyword typedef is superfluous; in your example, it is completely equivalent to: enum test { one }; Another place where it...
6,399,943
6,399,956
C++ link error LNK2005
I am new to C++ programing and I'm trying to make a program that simulates Conway's game of life. I'm almost done but when I made each function have it's own file I keep on getting this linker error. 1>algorithm_change.obj : error LNK2005: "unsigned short height" (?height@@3GA) already defined in algorithm.obj My code...
Without looking at the code, do you have a global unsigned short height; in any header file? If yes, replace that with extern unsigned short height; and put a unsigned short height; in a source file that includes the specific header.
6,400,014
6,400,021
How to make a reference parameter in a function optional (optional buffer)
So I'm making a function that detects collisions between two sprites, and would like to add two buffers as optional parameters to be filled with the angle of the sides of each objects collision. However this means the two buff parameters must be references, and must be there whenever the function is called, and I am n...
You can overload the function. Just define a second wrapper function like so: bool CheckCollision(T *obj1, T *obj2) { float dummy1, dummy2; return CheckCollision(obj1, obj2, dummy1, dummy2); } And define a second one for when only one float is provided, if you like.
6,400,044
6,400,056
Calculator which can take words as input
I want to write a calculator which can take words as input. for e.g. "two plus five multiply with 7" should give 37 as output. I won't lie, this is a homework so before doing this, I thought if I can be pointed to something which might be useful for these kinds of things and I am not aware of. Also, approach n how to d...
As long as the acceptable input is strict enough, writing a recursive descent parser should be easy. The grammar for this shouldn't differ much from a grammar for a simple calculator that only accepts digits and symbols. With an std::istream class and the extraction operator (>>) you can easily break the input into sep...
6,400,047
6,400,152
Error when trying to use functions from dlls
My code: dll: #include "stdafx.h" #include <iostream.h> extern "C" __declspec(dllexport) void F1() { cout << "It works\n"; } extern "C" __declspec(dllexport) int F2() { return 154827; } extern "C" __declspec(dllexport) void F3(int n) { cout << "It works: "<<n<<"\n"; } extern "C" __declspec(dllexport) in...
What's likely happening is that your DLL and your executable are linking against different versions of the C++ runtime library. Since there are now two different versions of the C++ runtime library living in your process's address space, there are two separate memory buffers being used for stdout. Since you're not fl...
6,400,283
6,401,064
Having issues using the cURL libraries for Dev-C++ in Windows 7
I reciently installed the cURL libraries in Dev-C++ using the Packman.exe which is included in the Dev-C++ install. When I try to use #include <curl/curl.h> I do not get an error, so I am assuming that it installed correctly. However, when I try and compile an example from the cURL website, I get the following errors: ...
There are a couple of ways you can add the .lib and/or .a files to the linker in Dev-C++: The following is what I did when completing the boost tutorial http://www.boost.org/doc/libs/1_46_1/more/getting_started/windows.html#link-your-program-to-a-boost-library : Project > Project Options > Directories > Library Direct...
6,400,369
6,400,389
Using Unions in Visual C++
I'm trying to use a Union in a Windows Forms application in C++. My code goes like this: union mytypes1_t { unsigned long mylong; char mychar; } mytypes1; After the includes at the top of my Form1.h file, and: for (int num = 0;num<3;num++) { mytypes1.mychar[0]='a'; } When a button is clicked. I get the error ...
Your mychar is not an array or pointer you could instead declare it like so: union mytypes1_t { unsigned long mylong; char mychar[4]; } mytypes1;
6,400,390
6,400,410
sync the same code blocks file across multiple computers
i have began coding on a separate computer from my home one and i am running code blocks off of a USB, but i have come across a problem when moving back to my home PC to use the same project. the problem is with syncing the files that have been updated on my USB back to my computer doing it manually is beginning to tak...
Use a version control system. Git would be a good choice, since you can set up a bare repository on the USB stick and sync with it from each machine. Git has a hefty learning curve, but the huge benefits to your workflow will be worth the effort many times over. Another choice is Mercurial. I strongly dislike Mercurial...
6,400,573
6,455,846
Is it possible to know what processes are running on a symbian phone with Qt?
I know its possible with Symbian C++ as the following code void GetProcessListL(void) { TFullName res; TFindProcess find; while(find.Next(res) == KErrNone) { RProcess ph; ph.Open(find); // here you can use // functions of the RProcess // to get more information // of the selected process. ...
According to a post on Qt Centre last year: What Qt APIs will I need to get the processes for the QStringList? Getting a string list will have to be done in native way, so I can't help you there. Here's an article on Nokia Developer about Using Qt and Symbian C++ Together using the PIMPL pattern, it shows ...
6,400,597
6,400,920
why does mbstowcs return "invalid multibyte character"
"קמ&quot;ד חיר!" is the input string copy pasted from a print of the variable in gdb. Calling mbstowcs returns -1 with the other input as NULL. Any ideas on what's wrong/how to fix this? "\327\247\327\236&quot;\327\223 \327\227\327\231\327\250!\000\000\000" is the string with non ascii characters in octal The programs ...
The mbtowcs function doesn't handle UTF-8 encoding, there isn't a locale you can set to have it translate UTF-8 to wchar_t. Therefore, I'll use Windows examples but the general idea is the same on most OS. In the multi-byte character set world there may not be one meaning for a given octal value and there may not be ...
6,400,899
6,402,518
C++ Event Tracing for Windows (ETW) wrapper
I have been investigating Event Tracing for Windows (ETW) for use within existing backend/server applications. MSDN and other sources have sold the power of the framework and its integration with xperf, etc. which frankly I am impressed with. However I am a bit concerned by the Win32 APIs and the overhead of working wi...
Rather than using the Win32 API directly, I would recommend using WPP. WPP is a pre-processor which allow you to write printf-like trace lines anywhere in your code and have the result of those, along with the additional data (e.g. the arguments passed to the various %d and %s in the trace) be logged to ETW. The defini...
6,400,950
23,256,908
How can I solve a conflict between openFrameworks and other audio applications?
When I try executing the audioOutputExample shipped with openFrameworks, I get RtApiAlsa::getDeviceIno: snd_pcm_open error for device (hw:0,0), Device or resource busy. RtApiAlsa::probeDeviceOpen: pcm device (hw:0,0) won't open for output. RtApi:: a stream is not open! Process returned 0 (0x0) execution time :...
I found a solution. The problem was, that I have two internal sound devices registered - HDMI and PCH. The HDMI device was always assigned to be card0, which can be checked by typing aplay -l into the terminal. This will list the different devices. I then changed my alsa configuration using gksudo gedit /etc/modprob...
6,401,013
6,401,029
How to make VS portable
I did some reading on IDE`s (I am currently using Code::Blocks) and everyone appears to think that VS is the best IDE but I am wondering if I can make it portable. For example installing it on a USB and have it work on a computer that has never had it installed before.
Quick version: No. VS is a huge application, it integrates with Windows at a low level in places: it is a native debugger. Additionally much of VS is built on COM, which requires registration.
6,401,036
6,401,052
Unicode Compiler error on simple function
Sigh I am working with the Microsoft Visual Express C++ IDE. I have recently transitioned from DevC++ to this IDE. I have a function that works perfectly in DevC++ but in MSVC++ it wont compile because of Unicode (I think?). What do I need to change to get my function to compile? See the commented code line for the com...
your project is a UNICODE build and you using ANSI strings, first thing to do is replacing your char variables to TCHAR and try again. And as @David Heffernan, aptly suggested, you will have to switch to wstring and aptly change the library functions from standard library which you use.
6,401,081
6,401,095
How to static_assert in member templates only when they are actually used?
Consider this simple class: template<class T> class Foo{ public: Foo(T const& val) : _val(val) {} template<class U> Foo(Foo<U> const&){ static_assert(false,"Cannot convert from Foo<U> to Foo<T>."); } operator T&() { return _val; } operator T const&() const{ return _val; } private: T _val; }; I...
It fails compilation, because compiler can clearly seestatic_assert would fail no matter what. It doesn't depend onU and T in any way. I think you wanted something like this: static_assert(std::is_same<T,U>::value,"Cannot convert from Foo<U> to Foo<T>.");
6,401,278
6,401,316
C++ Constructor for Implicit Type Conversion
I have these codes: class Type2 { public: Type2(const Type1 & type); Type2(int); const Type2 & operator=(const Type2 & type2); //.... }; ... Type1 t1(13); Type2 t2(4); t2=t1; As I understood, the 1-argument constructors of Type2 each without an explicit keyword should mean any Type1 objects or int values c...
I've found the answer. Because my Type1 got a conversion operator class Type1 { public: Type1 (int ); operator Type2() ;//casting to Type2 .... }; This is something called "dual-direction implicit conversion"
6,401,286
6,411,428
When is %destructor invoked in BISON?
When is %destructor invoked in BISON? I have the following bison code: %union{ char * sval; Variable * vval; } %token VARIABLE %token Literal %type <vval> Expression VARIABLE %type <sval> Literal %destructor { delete $$; } <vval> %destructor { delete $$; } Literal where Variable is a class. I though...
I figured out, that I should free() it after I perform the action, so for example ... | String CONCAT String { $$ = concat($1,$3); free($1); free($3); } ... That did the trick for me.
6,401,406
6,401,429
C++ - Accessing a file that was "dropped" on the executable
I have used a number of programs where I am able to use the programs functions by simply dragging and dropping a file onto the executable. For example, if there is a program that formats text files, simply dragging a text file onto the executable will make it run and use the text file as the target. What does the main ...
Dropped files are usually just given as command line parameters to the program: int main(int argc, char** argv) { if (argc > 1) { // do sth. with argv[1] == first dropped file name } }
6,401,460
6,401,505
defining a public struct inside a class
Hey so i'm making a function that gathers up sprites that you wanna keep on screen, and then "Check()s" them to make shure they stay, making them bounce of the edge of the screen otherwise. I have defined a struct inside my class ('Object') which holds a refrence to the sprite, and whether it's still outside the scre...
Will saving a refrence to a sprite in my Object struct allow me to reach the original sprite, and not just a copy when calling reflect()? References need to be initialize at the time of creation and they remain bound to the type object they are alias to So Saving a reference to sprite will always keep pointing to the s...
6,401,717
6,401,907
How to create a fullscreen OpenGL-ES renderview in Windows?
I'm using cocos2d-x to develop an iPhone game and then it just came to my head why not release my game for PC too? The only problem is that setting the window to full screen mode is not implemented yet. Now I'm just stuck with how to create a full screen window? There are some window creation functions that are used bu...
On Windows it's a bit more compilicated. Essentially you have to: Create a proxy OpenGL context to get access to functionality above OpenGL-1.1 through extensions Load the extensions required to create an OpenGL-ES compatible context Create the higher version OpenGL context Again Load the extensions, now for this cont...
6,401,818
6,402,127
Non-const copy constructor and implicit conversions on return value
Consider the following C++ code: struct B { }; struct A { A(int); A(A&); // missing const is intentional A(B); operator B(); }; A f() { // return A(1); // compiles fine return 1; // doesn't compile } This compiles fine on MSVC++ 2010 (in fact, on MSVC it even works if I...
The error is quite clear on the list of candidates that were rejected. The problem is that implicit conversion sequences involving a user defined conversion in the C++ language are limited to a single user defined conversion: §13.3.3.1.2 [over.ics.user]/1 A user-defined conversion sequence consists of an initial stand...
6,402,123
6,402,205
QT, concurrency programming and passing parameters to function
I have a QList and want to process all its elements in parallel. The problem is I need to pass an argument to my_function. The code below doesn't allow for this. QList<something> output = QtConcurrent::blockingMapped( input, my_function ); I may use a distinct function for each set of parameters. I may use a g...
Assuming that the argument you want to pass to the function is independent of the items, you can create a functor that extends std::unary_function<const something&,void> whose constructor takes the argument you want to pass to it. Then, use the functor where you would use the function. E.g., struct MyFunctor : public s...
6,402,379
6,402,468
Adding options for your application to the Windows Explorer context menu
You know how when you right click on something in explorer there are options for your antivirus, ZIP archive manager, etc? I was wondering how one might add options for their own application to the context menu. After a failed search for the answer on the internet, I came here. Thanks for your help. (I doubt it's relev...
You need to create a shell extension handler, a context menu extension handler in your case. Covered well in this series of tutorials, part 1 talks about menus and how to install and debug these handlers.
6,402,387
6,402,772
Does template (meta)programming has always only one way of implementation?
Studying few of the template programs and especially meta programs which deduce result at compile time into a constant, I learned that generally there is only one way to implement something. e.g.: as easy as factorial example or as complex as is_base_of I am never able to think about perfect alternate implementation of...
Generally speaking, the lack of features available in TMP and the relative simplicity of the functionality- if not the way it has to be expressed- means that there's very rarely more than one implementation that differs significantly.
6,402,586
6,403,559
know if .lib is static or import
I have .lib file compiled from C code. How I know if this self-contained static library or just an import lib and DLL will be needed at runtime? Is there some dumpbin option I'm missing?
Use the lib command. If it's static, lib will show you a pile of .obj files inside. Not so if it's am implib. lib /list foo.lib will do it. Also see: https://learn.microsoft.com/en-us/cpp/build/reference/managing-a-library
6,402,590
6,403,394
Help Editing Code to Fix "Argument list too long" Error
I am currently doing some testing with a new addition to the ICU dictionary-based break iterator. I have code that allows me to test the word-breaking on a text document but when the text document is too large it gives the error: bash: ./a.out: Argument list too long I am not sure how to edit the code to break-up the a...
The code below reads the content of a file whos name is given as the first parameter on the command-line and places it in a str::buffer. Then, instead of calling the function UnicodeString with argv[1], use that buffer instead. #include<iostream> #include<fstream> using namespace std; int main(int argc, char **argv) ...
6,402,666
6,402,705
How to return CArray?
Which way is good for returning an array of classes? class BigSizeClass { int data[1024 * 1024]; }; Very bad and expensive way: CArray<BigSizeClass> test() { CArray<BigSizeClass> ret; for(int i = 0; i < 1024; i++) { BigSizeClass c; ret->Add(c); } return ret; } may be I forget delete returning val...
Way 1 is just fine. RVO and NRVO will kick in here. Even if it doesn't you can still "swaptimize", assuming that CArray does the smart thing and has a swap function. CArray<BigSizeClass> result; test().swap(result); However, I'd have to recommend against the use of CArray- it doesn't use the copy constructor but inste...
6,402,703
6,403,401
Using allocators to replace malloc()/free()?
Is there any portable way to replace usage of malloc()/free() with wrappers around STL-like allocators? The context: I have a C library that allows to specify custom malloc()/free()-like functions for memory management, and which is used in multi-threaded contexts. Looking around for a good multi-threaded allocator, I'...
On my platform, malloc ensures that allocated memory is aligned at an 8-byte boundary. To mimic this behavior, use an allocator<uint64_t>: #include <stdint.h> #include <ext/mt_allocator.h> static __gnu_cxx::__mt_alloc<uint64_t> theAllocator; void* mtmalloc(size_t size) { // Divide size by sizeof(uint64_t) and rou...
6,402,754
6,402,965
Sqlite c/c++ api who is respnsible for freeing pointer from sqlite3_column_text
The function sqlite3_column_text returns const char* Should I free the returned pointer or sqlite will free it?
sqllite will free it. check here the quote from sqllite api reference: The pointers returned are valid until a type conversion occurs as described above, or until sqlite3_step() or sqlite3_reset() or sqlite3_finalize() is called. The memory space used to hold strings and BLOBs is freed automatically. Do not pass the p...
6,402,942
6,402,957
Will the erase function of set in C++ change the address of other elements?
I have the following code: set<Key> test; test.insert(key1); test.insert(key2); iter1 = test.find(key1); iter2 = test.find(key2); test.erase(iter1); My question is, if key1 is deleted, now can I use iter2 to refer to key2 in test? Thanks
Yes, set's erase invalidates only iterators that point to the element that was erased (note that this is not necessarily true for all containers).
6,403,078
6,403,721
converting strings from a map to a 2d vector character-wise
I have an array of strings which need to be taken into a map. Since the array size is variable, I need a 2d vector to obtain the string character-wise. i need both formats of storage for operations i perform on them. Here's my attemp..gives errors in (EDIT:)run time. #include "stdafx.h" #include<iostream> #include<stri...
It looks like the problem occurs after you print out the map, before you copy the strings into the vector. You need two things: while(p!=row.end()) { cout<<(p->first)<<","<<(p->second)<<"\n"; p++; } p = row.begin(); // Must reset iterator! vector<vector<char>>matrix(r,vector<char>(c)); rep(i,0,r){ int k=...
6,403,212
6,403,296
Container to hold URI host names
I've run into a problem that might require the use of a more unusual data structure, but I'm not sure. Essentially, I want to store URI hostnames in a container, and be able to query the container to tell whether or not a hostname exists in the container. However, if the container contains a higher-level domain of a c...
A simple solution, reverse the node order (ie. make www.example.com into com.example.www) and stuff that into your Patrica Trie. then you can traverse the trie until you find your match in one go