This is a complaint about STL. Why do they take filename arguments as (char *) and not as std::string? This seems to make no sense.
There are two other questions on this topic:
How to open unicode filenames with
STL
Windows Codepage interactions with
C++
The issue is that I have a lot of code that looks like this:
std::ofst...
Hi,
I need to remove elements from the middle of a std::vector.
So I tried:
struct IsEven {
bool operator()(int ele)
{
return ele % 2 == 0;
}
};
int elements[] = {1, 2, 3, 4, 5, 6};
std::vector<int> ints(elements, elements+6);
std::vector<int>::iterator it = std::remove_if(ints.begin() + 2, ints.begin...
I have a struct that I'd like to output using either 'std::cout' or some other output stream.
Is this possible without using classes?
Thanks
#include <iostream>
#include <fstream>
template <typename T>
struct point{
T x;
T y;
};
template <typename T>
std::ostream& dump(std::ostream &o,point<T> p) const{
o<<"x: " << p.x <<"\ty: "...
Hello,
I am doing some COM related things with directshow such as:
typedef CComPtr<IBaseFilter> AutoIBaseFilterPtr;
map<CString, AutoIBaseFilterPtr> _filterMap;
To store a list of directShow related com objects and their friendly name.
After finding this article (See:Problem 2) on how changes in VC10 compiler might effect previous...
Suddenly in this article ("problem 2") I see a statement that C++ Standard prohibits using STL containers for storing elemants of class if that class has an overloaded operator&().
Having overloaded operator&() can indeed be problematic, but looks like a default "address-of" operator can be used easily through a set of dirty-looking cas...
Code with iterators looks pretty much like code with pointers. Iterators are of some obscure type (like std::vector<int>::iterator for example).
What I don't get is how iterators and pointer are related to each other - is an iterator a wrapper around a pointer with overloaded operations to advance to adjacent elements or is it something...
According to C++ standard (3.7.3.2/4) using (not only dereferencing, but also copying, casting, whatever else) an invalid pointer is undefined behavior (in case of doubt also see this question). Now the typical code to traverse an STL containter looks like this:
std::vector<int> toTraverse;
//populate the vector
for( std::vector<int>::i...
I am currently using the STL included with the iPhone SDK. I haven't been able to find a way in the Xcode debugger to look at data that is in a list, map, etc. like I can within Visual Studio. Within Visual Studio, I can walk through the data structure and look at the data within the list, map, etc. Within Xcode, this doesn't seem to ...
I've enabled iterator debugging in an application by defining
_HAS_ITERATOR_DEBUGGING = 1
I was expecting this to really just check vector bounds, but I have a feeling it's doing a lot more than that. What checks, etc are actually being performed?
Dinkumware STL, by the way.
...
Hi dear all,
I am a newbie to c++ STL vectors so sorry for silly questions in advence. :)
In my program, I have a vector which needs to store unknown number of elements.
Do I have to check if the vector has achieved its max_size before adding an new element to it ?
Will a c++ compiler throw an exception automatically when a program trie...
I've got a two vectors in class A that contain other class objects B and C. I know exactly how many elements these vectors are supposed to hold at maximum. In the initializer list of class A's constructor, I initialize these vectors to their max sizes (constants).
If I understand this correctly, I now have a vector of objects of class ...
I'm building an interpreter and as I'm aiming for raw speed this time, every clock cycle matters for me in this (raw) case.
Do you have any experience or information what of the both is faster: Vector or Array?
All what matters is the speed I can access an element (opcode receiving), I don't care about inserting, allocation, sorting, et...
Like this question already asked, I'd like to initialize a container using STL where the elements are hard-coded in the cleanest manner possible. In this case, the elements are a doubly nested container:
set<vector<int> > A;
And I'd like (for example) to put the following values in:
A = [[0,0,1],[0,1,0],[1,0,0],[0,0,0]];
C++0x fine...
class MyClass
{
public:
void setVar(const char *str);
private:
std::string mStr;
int maxLength; //we only store string up to this length
};
What's the best approach to implement setVar when the external code is quite likely to pass in NULL for an empty string (and cannot be changed)? I currently do something a bit like:
void M...
I've clearly been stuck in Java land for too long... Is it possible to do the C++ equivalent of the following Java code:
interface Foo {}
class Bar implements Foo {}
static List<Foo> getFoo() {
return new LinkedList<Foo>();
}
static List<Bar> getBar() {
return new LinkedList<Bar>();
}
List<? extends Foo> stuff = getBar();
Wher...
Trivial code that works if I do not overload myfunc.
void myfunc(int i)
{
std::cout << "calling myfunc with arg " << i << std::endl;
}
void myfunc(std::string s)
{
std::cout << "calling myfunc with arg " << s << std::endl;
}
void testalgos()
{
std::vector<int> v;
v.push_back(1);
v.push_back(2);
std::vector<std::...
I have a C++ function that produces a list of rectangles that are interesting. I want to be able to get that list out of the C++ library and back into the C# application that is calling it.
So far, I'm encoding the rectangles like so:
struct ImagePatch{
int xmin, xmax, ymin, ymax;
}
and then encoding some vectors:
void MyFunc(....
I would like to copy the content of one std::map into another. Can I use std::copy for that? Obviously, the following code won't work:
int main() {
typedef std::map<int,double> Map;
Map m1;
m1[3] = 0.3;
m1[5] = 0.5;
Map m2;
m2[1] = 0.1;
std::copy(m1.begin(), m1.end(), m2.begin());
return 0;
}
This won't work because co...
std::vector<T> vec; // line #1
vec.reserve(100); // line #2
I am wondering if line #1 triggers a small allocation (say, memory for 10 Ts), or if the first allocation happens on line #2. Does the standard say anything about that?
...
I have do an extensive calculation on a big vector of integers. The vector size is not changed during the calculation. The size of the vector is frequently accessed by the code. What is faster in general: using the vector::size() function or using helper constant vectorSize storing the size of the vector?
I know that compilers usually a...