- , , , - . , , .
//
//
const char * ToString (char _sep) const
{
//
static char tempBuf[ 11 ];
sprintf(tempBuf, "%d%c%d%c%d", m_Year, _sep, m_Month, _sep, m_Day);
return tempBuf;
}
// -
Date d(2013, 5, 3);
const char * str = d.ToString('/');
std::cout << str << std::endl;
-, .
-. . , -, const, .
, - , , , mutable. - - const.
//
// . const-
mutable char m_tempBuf[ 10 ];
public:
//...
//
const char * ToString (char _sep) const
{
//
sprintf(m_tempBuf, "%d%c%d%c%d", m_Year, _sep, m_Month, _sep, m_Day);
return tempBuf;
}
ToString Date, , , . -, , , , :
. const-
mutable char m_tempBuf[ 10 ];
//
mutable bool m_BufferValid;
false
false
//
|
|
const char * ToString (char _sep) const
{
//
if (! m_BufferValid)
{
//
sprintf(m_tempBuf, "%d%c%d%c%d", m_Year, _sep, m_Month, _sep, m_Day);
//
m_Buffervalid = true;
}
return tempBuf;
}
, , .
//
struct StringRepr
{
char m_tempBuf[ 10 ];
bool m_isValid;
}
StringRepr* m_pStringRepr;
, - , , .
20. std::string . , . .
, , ++. , , , . , , , , strcpy strcmp, .
- , ++, . , std::string, <string>.
, , . , ( 16 ), , . , . , std::string .
, std::string , , , .
std::string , :
● [] ;
● +, += ;
● (==,!=, <, <=, >, >=);
● <<, >> (, ).
- , , .. .
|
|
, std::string , . :
● size, length - ;
● empty - ;
● reserve, capacity - ;
● clear - ;
● insert/erase - / ;
● replace - ;
● find, rfind, find_first_of, find_last_of - ;
● substr - ;
● _str - ( const char *).