Article ID: 157433
Article Last Modified on 7/13/2005
<string>
size_type size() const; void resize(size_type n, E c = E());
resize is defined in header xstring which is included indirectly.Note The class/parameter names in the prototype may not match the version in the header file. Some have been modified to improve readability.
//////////////////////////////////////////////////////////////////////
//
// Compile options needed: /GX
//
// <filename> : size.cpp
//
// Functions:
//
// size()
// resize() ; Defined in header xstring which is included indirectly.
//
// Written by Linda Koontz
// of Microsoft Product Support Services,
// Copyright (c) 1996 Microsoft Corporation. All rights reserved.
//////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#if _MSC_VER > 1020 // if VC++ version is > 4.2
using namespace std; // std c++ libs implemented in std
#endif
void main()
{
string TestString = "1111122222333334444455555";
cout << TestString << "\n size: " << TestString.size() << endl;
TestString.resize(5);
cout << TestString << "\n size: " << TestString.size() << endl;
TestString.resize(10);
cout << TestString << "\n size: " << TestString.size() << endl;
TestString.resize(15,'6');
cout << TestString << "\n size: " << TestString.size() << endl;
}
Output is: 1111122222333334444455555 size: 25 11111 size: 5 11111 size: 10 11111 66666 size: 15
Additional query words: STL STLSample size resize
Keywords: kbhowto kbinfo kbtemplate kbstl kbcode kbfunctions KB157433