Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Search the Tips
Tip Bank > C++ > STL

STL - Page 2

21-40 of 87     Previous     Next
Creating a Temporary File
by Danny Kalev
Many applications create temporary files that exist as long as the program is running and are later discarded. For example, a Web browser can store a list of pages that have been viewed during the ...
The vector::data() Member Function
by Danny Kalev
In a previous tip, I discussed techniques for treating a vector object as an array. The two main forms of obtaining the internal array's address ...
Treating a Vector As an Array
by Danny Kalev
In certain contexts, you have to treat a vector as an array of its elements. For example, suppose you have a function that takes int * as its argument. How can you pass a vector of int's as an ...
The Semantics of const_iterator
by Danny Kalev
A recent subscriber of one of the C++ newsgroups posted the following ...
The erase() Member Function of Associative Containers
by Danny Kalev
The associative containers std::map, std::multimap, std::set, and std::multiset have the following three overloaded forms of the member function ...
The fill() Algorithm
by Danny Kalev
The algorithm fill() is declared in <algorithm> as ...
Container of Pointers
by Danny Kalev
Many programmers believe that by storing pointers instead of objects in a container, they improve performance. However, they forget that the pointers still refer to existing objects that must be ...
Simulating Multidimensional Arrays Using Vectors
by Danny Kalev
Although you can allocate multidimensional arrays manually, as ...
Derive from STL Map<>
by DevX Pro
I created my own map class (called it Mapper) by creating a template class and deriving from STL map container class. I did so because I wanted to have some extra user-defined methods in this class. I don't have any problems compiling if I only use the methods provided by the STL map class. However, when I try to make a call to one of the new methods in Mapper, I get the following linking error: --------------------Configuration: mapfunc - Win32 Debug-------------------- Compiling... runmapper.cpp Linking... runmapper.obj : error LNK2001: unresolved external symbol "public: int __thiscall Mapper::SmartMatch(class std::basic_stringshort>,class std::allocator > const &)" (?SmartMatch@?$ Mapper@H@@QAEHABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z) Debug/mapfunc.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. mapfunc.exe - 2 error(s), 0 warning(s) By the way, runmapper.cpp is the driver program and mapfunc is the project name. I have three user-defined methods (one of them is SmartMatch(key)) that when I try to call, from the driver program, give me the same compilation error (linking error).
The pow() Function
by Danny Kalev
The Standard Library provides the pow() functions (declared in <math.h>) which takes two arguments of type double, x and y: double powl(double x, double ...
Inserting Different Types of Objects in STL Lists
by DevX Pro
I need a container of different objects. I have made all derived classes of the same base class and pushed them onto the container. The problem then arises in getting them off the container, i.e., base class synObject, and synPin and synPin derived: class synObject { public : synObject(); string GetClass(); string className; }; synObject::synObject() { className = "synObject"; } string synObject::GetClass() { return className; } class synPin : public synObject { string pin; public : synPin(); void SetPin(string Pin); string GetPin(); private: }; synPin::synPin() { className = "synPin"; } void synPin::SetPin(string Pin) { pin = Pin; } string synPin::GetPin() { return pin; } class synCell : public synObject { string cell; public : synCell(); void SetCell(string Cell); string GetCell(); private: }; synCell::synCell() { className = "synCell"; } void synCell::SetCell(string Cell) { cell = Cell; } string synCell::GetCell() { return cell; } I then use the classes, and push to a list of vector pointers. synObject * pMyObject; pMyObject = new synObject; synPin * pMyPin; pMyPin = new synPin; (*pMyPin).SetPin("myPin"); synCell * pMyCell; pMyCell = new synCell; (*pMyCell).SetCell("myCell"); vector MyVector; vector::iterator ThisVector; MyVector.empty(); MyVector.push_back(pMyObject); MyVector.push_back(pMyPin); MyVector.push_back(pMyCell); When I come to iteregate the vector though, I can only access the common (base) methods: not those derived from the base class. for ( ThisVector = MyVector.begin(); ThisVector != MyVector.end(); ThisVector++ ) { cout
Improving the Usage of Dynamically Allocated Objects
by Danny Kalev
Suppose you need to fill a container with pointers to objects instead of actual objects. Usually, you do this when you want to store objects of different types in the same container. To do that, you ...
Equivalence Relationship in STL
by Danny Kalev
Certain STL containers and algorithms require that you overload operator < for the class type they store as elements in order to sort and compare these elements. Note that STL derives the equality ...
Deleting a File
by Danny Kalev
The standard function remove() deletes a file. It takes one argument of type const char * which is the name of the file to be deleted. You can provide a full path as a filename. On success, remove() ...
Renaming a File
by Danny Kalev
To rename a file, use the standard function rename() (declared in <stdio.h>). This function takes two arguments of type const char *, the first of which is the old name and the second one is the ...
Understanding Iterator Categories
by Danny Kalev
The Standard Template Library defines five major categories of iterators. The following diagram illustrates these ...
Transforming a String to Uppercase Letters
by Danny Kalev
To change the case of all the letters in a string object, use the std::transform() algorithm. This algorithm is defined in the standard header <algorithm>. It takes four arguments. The first two ...
Forward Declaration for STL String Class
by DevX Pro
How do I do a forward declaration for the STL 'string' class? For example: // Foo.hpp class string; class Foo { string f1(); void f2(const string& str); ... } On various compliers (MS, Sun, GNU) this produces error messages to the effect of "invalid class definition" or "conflicting class definition."
Prefer Stringstream Objects to Strstream Objects
by Danny Kalev
In pre-standard C++, the strstream family of classes was used as buffered stream classes. These classes are now considered deprecated; you should use the stringstream family of classes instead. For ...
STL Set Performance
by DevX Pro
How do I improve an integer set's performance when it is used in multithreaded environment?
21-40 of 87     Previous     Next
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date