std

VC++ linker errors on std::exception::_Raise and std::exception::exception

I am using Visual C++ 2005 Express Edition and get the following linker errors: 19>mylib1.lib(mylibsource1.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::exception::_Raise(void)const " (__imp_?_Raise@exception@std@@QBEXXZ) referenced in function "protected: static void __cdecl std::v...

How do I use std::tr1::mem_fun in Visual Studio 2008 SP1?

The VS2008 SP1 documentation talks about std::tr1::mem_fun. So why, when I try and use std::tr1::mem_fun, why do I get this compile error?: 'mem_fun' : is not a member of 'std::tr1' At the same time, I can use std::tr1::function without problems. Here is the sample code I am trying to compile, which is supposed to call TakesInt on a...

What function in the std library is there to binary search a vector and find an element?

I've got a node struct struct Node{CString text, int id;}; in a sorted vector. I'm wondering if there's a function in algorithm that will do a binary search of the vector and find an element. ...

Is there a standard C++ function object for taking apart a std::pair?

Does anyone know if there's a de-facto standard (i.e., TR1 or Boost) C++ function object for accessing the elements of a std::pair? Twice in the past 24 hours I've wished I had something like the keys function for Perl hashes. For example, it would be nice to run std::transform on a std::map object and dump all the keys (or values) to ...

Why does std::auto_ptr operator = trash objects?

Seem to be having an issue with std::auto_ptr and assignment, such that the object referenced seems to get trashed for some reason. std::auto_ptr<AClass> someVar = new AClass(); // should work, but mangles content std::auto_ptr<AClass> someVar( new AClass() ); // works fine. std::auto_ptr<AClass> someVar = std::auto_ptr<AClass>(new ACl...

mem_fun fails, pthread and class ptr

pthread takes in as its parameter void (start_routine)(void* userPtr), i was hoping i can use std::mem_fun to solve my problem but i cant. I would like to use the function void * threadFunc() and have the userPtr act as the class (userPtr->threadFunc()). Is there a function similar to std::mem_func that i can use? ...

ifstream, end of line and move to next line?

how do i detect and move to the next line using std::ifstream? void readData(ifstream& in) { string sz; getline(in, sz); cout << sz <<endl; int v; for(int i=0; in.good(); i++) { in >> v; if (in.good()) cout << v << " "; } in.seekg(0, ios::beg); sz.clear(); getline(in, sz); cout...

How do I write binary data for 7z archive format?

I've been pouring over the format description and source code for the 7z archive format, but I'm still having trouble writing a valid container. I assume I can create an empty container... anyway here's my start: std::ofstream ofs(archivename.c_str(), std::ios::binary|std::ios::trunc); Byte signature[6] = {'7', 'z', 0xBC, 0xAF, 0x27,...

creating an ostream

I am trying to create a c++ ostream for educational reasons. My test will be creating an ostream that acts like a ofstream would except instead of writing to a file it would write to a deque or vector container. ...

How to find an item in a std::vector?

All I wanna do is to check whether an element exists in the vector or not, so I can deal with each case. if ( item_present ) do_this(); else do that(); ...

container for quick name lookup

I want to store strings and issue each with a unique ID number (an index would be fine). I would only need one copy of each string and I require quick lookup. I check if the string exist in the table often enough that i notice a performance hit. Whats the best container to use for this and how do i lookup if the string exist? ...

Is there a better way to reverse an array of bytes in memory?

typedef unsigned char Byte; ... void ReverseBytes( void *start, int size ) { Byte *buffer = (Byte *)(start); for( int i = 0; i < size / 2; i++ ) { std::swap( buffer[i], buffer[size - i - 1] ); } } What this method does right now is it reverses bytes in memory. What I would like to know is, is there a better way to g...

Does std::vector.clear() do delete (free memory) on each element?

Consider this code: #include <vector> void Example() { std::vector<TCHAR*> list; TCHAR* pLine = new TCHAR[20]; list.push_back(pLine); list.clear(); // is delete called here? // is delete pLine; necessary? } Does list.clear() call delete on each element? I.e. do I have to free the memory before / after list.clea...

Can you remove elements from a std::list while iterating through it?

I've got code that looks like this: for (std::list<item*>::iterator i=items.begin();i!=items.end();i++) { bool isActive = (*i)->update(); //if (!isActive) // items.remove(*i); //else other_code_involving(*i); } items.remove_if(CheckItemNotActive); I'd like remove inactive items immediately after update them, ...

C++ select first not null element

Guys, [question update according to updated requirements] I've implemented following function which should return either first not null element or throw an exception. Also could you invent more classic and shorter name like 'max', 'min', 'pair'? template <typename T> T select_first_not_empty( const T& a, const T&b ) { static T null...

Why is stringstreams rdbuf() and str() giving me different output?

I have this code, int main() { std::string st; std::stringstream ss; ss<<"hej hej med dig"<<std::endl; std::getline(ss,st,' '); std::cout <<"ss.rdbuf()->str() : " << ss.rdbuf()->str(); std::cout <<"ss.rdbuf() : " << ss.rdbuf(); return 0; } Giving me this output ss.rdbuf()->str() : hej hej med dig ...

using BOOST_FOREACH with std::map

I'd like to iterate over a std::map using BOOST_FOREACH and edit the values. I can't quite get it. typedef std::pair<int, int> IdSizePair_t; std::map<int,int> mmap; mmap[1] = 1; mmap[2] = 2; mmap[3] = 3; BOOST_FOREACH( IdSizePair_t i, mmap ) i.second++; // mmap should contain {2,3,4} here Of course this doesn't change anything...

Are there any practical limitations to only using std::string instead of char arrays and std::vector/list instead of arrays in c++?

I use vectors, lists, strings and wstrings obsessively in my code. Are there any catch 22s involved that should make me more interested in using arrays from time to time, chars and wchars instead? Basically, if working in an environment which supports the standard template library is there any case using the primitive types is actually ...

const unsigned char * to std::string

sqlite3_column_text returns a const unsigned char*, how do I convert this to a std::string? I've tried std::string(), but I get an error. Code: temp_doc.uuid = std::string(sqlite3_column_text(this->stmts.read_documents, 0)); Error: 1>.\storage_manager.cpp(109) : error C2440: '<function-style-cast>' : cannot convert from 'const unsig...

CLR interfering with C++ STD?

I have some code compiling under the clr and other code that is unmanaged in a single project. My common.h file includes all the std library headers that I need. It is included by manager.h (forward declaration for manager.cpp (no CLR)), which is included by main_window.h (WinForm) which is included by document_manager.cpp (CLR). At r...