I am trying to compare two vector objects, and return a single vector containing all the chars which appear in both vectors.
How would I go about this without writing some horribly complex manual method which compares every char in the first vector to every char in the second vector and using an if to add it to a third vector (which wou...
I have a process under the Run key in the registry. It is trying to access an environment variable that I have defined in a previous session. I'm using ExpandEnvironmentStrings to expand the variable within a path. The environment variable is a user profile variable. When I run my process on the command line it does not expand as well. I...
Will auto_ptr be deprecated in incoming C++ standard?
Should unique_ptr be used for ownership transfer instead of shared_ptr?
If unique_ptr is not in the standard, then do I need to use shared_ptr instead?
...
I need to save all ".xml" file names in a directory to a vector. To make a long story short, I cannot use the dirent API. It seems as if C++ does not have any concept of "directories".
Once I have the filenames in a vector, I can iterate through and "fopen" these files.
Is there an easy way to get these filenames at runtime?
...
Can anybody explain the difference between cerr cout and clog and why does different objects are proposed?
I know the differences are as below:
1) cout can redirected but cerr can't
2) clog can use buffer.
I am confused about the point 2, I am grateful if anybody can elaborate it more.
...
In the following code, the stack-based variable 'ex' is thrown and caught in a function beyond the scope in which ex was declared. This seems a bit strange to me, since (AFAIK) stack-based variables cannot be used outside the scope in which they were declared (the stack is unwound).
void f() {
SomeKindOfException ex(...);
throw ...
It seems like I should be able to perform bit shift in C/C++ by more than 32 bits provided the left operand of the shift is a long. But this doesn't seem to work, at least with the g++ compiler.
Example:
unsigned long A = (1L << 37)
gives
A = 0
which isn't what I want. Am I missing something or is this just not possible?
-J
...
Hi everybody.
I have an extensible product that allows 3rd party developers to write plugins for it. The aspects that can be extended are documented and interfaces are provided in the SDK. Currently, I'm using COM and I'm getting pretty comfortable with it. I especially like the ability to provide interface versioning in a unified manne...
How do I reliably get the size of a C-style array? The method often recommended seems to be to use sizeof, but it doesn't work in the foo function, where x is passed in:
#include <iostream>
void foo(int x[]) {
std::cerr << (sizeof(x) / sizeof(int)); // 2
}
int main(){
int x[] = {1,2,3,4,5};
std::cerr << (sizeof(x) / sizeof...
is it possible to insert a new element to std::set like in case of std::list for example:
//insert one element named "string" to sublist of mylist
std::list< std::list<string> > mylist;
mylist.push_back(std::list<string>(1, "string"));
Now, mylist has one element of type std::string in its sub-list of type std::list.
How can you do ...
I have a major amount of memory leaks. I know that the Sets have pointers and i cannot change that! but clean up the mess i have...
I am creating memory with new in just about every function to add information to the sets.
here is my potential leaks..
library.cpp
#include "Library.h"
#include "book.h"
#include "cd.h"
#include "dvd.h"...
Hi! I would like to have a manager process sharing graphs via shared memory, read-only for other processes which will run various graph algorithms on these graphs. I would like to ask some questions emerged while researching the issue:
Are there any graph libraries which are able to operate on (possibly their own) graph structures in r...
I created a class "Entry" to handle Dictionary entries, but in my main(), I create the Entry() and try to cout the char typed public members, but I get garbage. When I look at the Watch list in debugger, I see the values being set, but as soon as I access the values, there is garbage. Can anyone elaborate on what I might be missing?
#...
While at university I started my first programming with ANSI C, before we moved onto Java later in the course. Now I would like to go back to (re)learning C and C++ again to allow me to contribute with open source projects and also to expand my CV and improve my career prospects.
Currently I mostly program in VB.net (I know I know, I t...
I am currently using Visual Studio Express C++ 2008, and have some questions about catch block ordering. Unfortunately, I could not find the answer on the internet so I am posing these questions to the experts.
I notice that unless catch (...) is placed at the end of a catch block, the compilation will fail with error C2311. For example...
I like the LWN article "Crash-only software" and I would like to learn more about crash-safe and fault-tolerant programming.
It is surprisingly hard to assure that the persistent state is consistent in fault situations. Here I do not even talk about distributed operations: That is hard on a single node, too: Even the normal Berkeley DB ...
Given the following piece of code, generating a kind of code dictionary with CUDA using thrust (C++ template library for CUDA):
thrust::device_vector<float> dCodes(codes->begin(), codes->end());
thrust::device_vector<int> dCounts(counts->begin(), counts->end());
thrust::device_vector<int> newCounts(counts->size());
for (int i = 0; i < ...
Hi, similar questions have been asked before but I cant find an exact match to my question.
I have 4 vectors each of which hold between 200-500 4 digit integers. The exact number of elements in each vector varies but I could fix it to a specific value. I need to find all possible combinations of the elements in these 4 vectors.
eg:
...
Consider the following code:
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
string myAry[] =
{
"Mary",
"had",
"a",
"Little",
"Lamb"
};
const size_t numStrs = sizeof(myStr)/sizeof(myAry[0]);
v...
When you allocate an array using new [], why can't you find out the size of that array from the pointer? It must be known at run time, otherwise delete [] wouldn't know how much memory to free...
Unless I'm missing something?
...