Possible Duplicate:
How do I iterate over cin line by line in C++?
I need to read all lines from a file:
std::ifstream file("...");
std::vector<std::string> svec(
(std::istream_iterator<std::string>(file)),
(std::istream_iterator<std::string>()),
);
but it is read as words.
...
I have a problem with stl priority queue.I want to have the priority queue in the increasing
order,which is decreasing by default.Is there any way to do this in priority queue.
And what is the complexity of building stl priority queue.If i use quick sort in an array which takes O(nlgn) is its complexity is similar to using priority que...
How do I delete all elements from a priority queue? That means how do I destroy a priority queue?
advanced thanks for your answer. Is there any clear- or erase-like method?
...
I've been trying to initialize a map of <ints, vector<ints> > using the new 0X standard, but I cannot seem to get the syntax correct. I'd like to make a map with a single entry with key:value = 1:<3,4>
#include <initializer_list>
#include <map>
#include <vector>
using namespace std;
map<int, vector<int> > A = {1,{3,4}};
....
It dies...
I started using stl containers because they came in very handy when I needed functionality of a list, set and map and had nothing else available in my programming environment. I did not care much about the ideas behind it. STL documentations were only interesting up to the point where it came to functions, etc. Then I skipped reading and...
As the question states ... i don't get the point about multisets / multimaps. So, what's the purpose?
...
I have an arbitrary STL container C, which contains elements of an arbitrary type T. I want to create an std::vector that has a copy of all the elements. What is the cleanest way to do this?
template <typename C>
void myfunction(C container){
/*Derive the type T of elements within the container*/
std::vector<T> mystack;
...
I am creating a windows app that uses a vector of stings as a member variable. For some reason, I can compile but when it tries to get at any of the vectors members is crashes. the error is 0xC0000005: Access violation reading location 0xcdcdcdd9. in the member function of the vector class.
this is the size() function where it breaks...
Hello,
I would like to fill my vector<float> from command line:
more my.txt | myexe.x > result.txt
What is the best way to open the pipe in C++?
Thanks
Arman.
...
I'm trying to get a simple delete every pointer in my vector/list/... function written with an ultra cool lambda function. Mind you, I don't know c**p about those things :)
template <typename T>
void delete_clear(T const& cont)
{
for_each(T.begin(), T.end(), [](???){ ???->delete() } );
}
I have no clue what to fill in for the ???'...
I have an application which is trying to populate a pair. Out of nowhere the application crashes.
The Windbg analysis on the crash dump suggests:
PRIMARY_PROBLEM_CLASS: INVALID_POINTER_READ
DEFAULT_BUCKET_ID: INVALID_POINTER_READ
STACK_TEXT:
0389f1dc EPFilter32!std::vector<std::pair<unsigned int,unsigned int>,std::allo...
I know containers of auto pointers should not be used and can cause problems. What is the actual reason for that? Is there any other kind of "smart" pointer which is safe to use in a container?
...
I need to go through a set and remove elements that meet a predefined criteria.
This is the test code I wrote:
#include <set>
#include <algorithm>
void printElement(int value) {
std::cout << value << " ";
}
int main() {
int initNum[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
std::set<int> numbers(initNum, initNum + 10);
// ...
I do not like using namespace std, but I am also tired of having to type std:: in front of every cout, cin, cerr and endl. So, I thought of giving them shorter new names like this:
// STLWrapper.h
#include <iostream>
#include <string>
extern std::ostream& Cout;
extern std::ostream& Cerr;
extern std::istream& Cin;
extern std::string& ...
Can C++ std::stack handle more than 10k int items? And how about its performance?
...
I frequently find myself requiring to iterate over STL vectors. While I am doing this I require access to both the vector element and its index.
I used to do this as:
typedef std::vector<Foo> FooVec;
typedef FooVec::iterator FooVecIter;
FooVec fooVec;
int index = 0;
for (FooVecIter i = fooVec.begin(); i != fooVec.end(); ++i, ++index)
...
hello.
Is it possible to do the following portably:
struct structure {
structure() {}
private:
// only allow container copy construct
structure(const structure&) {}
// in general, does not work because allocator (not vector) calls copy construct
friend class std::vector<structure>;
};
example message trying to com...
I have a method as follows (from a class than implements TBB task interface - not currently multithreading though)
My problem is that two ways of accessing a vector are causing quite different behaviour - one works and the other causes the entire program to bomb out quite spectacularly (this is a plugin and normally a crash will be caugh...
I am trying to use qsort from STL to sort array of edge:
struct edge
{
int w,v,weight;
};
by weight. What I am trying is:
int compare_e(const void *a, const void *b)
{
return ( *(edge *)a->weight - *(edge *)b->weight );
};
But I get:
`const void*' is not a
pointer-to-object type
EDIT:
Ok thx, now my code is compil...
Hi,
I have an issue with the following code :
class quicksort {
private:
void _sort(double_it begin, double_it end)
{
if ( begin == end ) { return ; }
double_it it = partition(begin, end, bind2nd(less<double>(), *begin)) ;
iter_swap(begin, it-1);
_sort(begin, it-1);
_sort(it, end);
}
public:
quicksort (){}
...