📄 mail_doc.cpp
字号:
//---------------------------------------------------------------------------
void PrintArguments()
{
cout << endl;
cout << "The current default data settings are: " << endl;
cout << endl;
cout << " " << PromptString1 << ParamString1 << "]" << endl;
cout << " " << PromptString2 << ParamString2 << "]" << endl;
cout << " " << PromptString3 << ParamString3 << "]" << endl;
cout << " " << PromptString4 << ParamString4 << "]" << endl;
cout << endl;
} // END PrintArguments()
//---------------------------------------------------------------------------
//
// Name:
// QueryArguments
//
// Description:
// Queries the user to change any of the input parameters.
// A carriage return on any of the prompts leaves it alone.
//---------------------------------------------------------------------------
void QueryArguments()
{
cout << endl;
cout << "Enter " << PromptString1 << ParamString1 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamString1 = CommandBuf;
cout << "Enter " << PromptString2 << ParamString2 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamString2 = CommandBuf;
cout << "Enter " << PromptString3 << ParamString3 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamString3 = CommandBuf;
cout << "Enter " << PromptString4 << ParamString4 << "]> ";
cin >> CommandBuf;
if( (CommandBuf) != (const char *)"" )
ParamString4 = CommandBuf;
} // END QueryArguments()
//===========================================================================
//
// IOPARAMETER Class Implementation
//
// Description:
// Implementation for a simple generic string buffer class
// to hold user input and output prompts.
//===========================================================================
//===========================================================================
// Constructors
//===========================================================================
IOParameter::IOParameter() // Default constructor.
{
size =1; // Null terminator.
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
pBuf[0] = '\0';
}
//===========================================================================
IOParameter::IOParameter( const char *str ) // Init with const string.
{
size = strlen(str) + 1; // size of string + null term.
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, str);
}
//===========================================================================
// Constructs a decimal radix string representation of an integer.
IOParameter::IOParameter( const int number )
{
char buf[16]; // Temporary buffer for characters.
sprintf(buf, "%d", number);
size = strlen(buf) + 1; // size of string + null term.
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, buf);
}
//===========================================================================
IOParameter::IOParameter( const IOParameter &Other ) // Copy constructor.
{
size = Other.size;
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, Other.pBuf);
}
//===========================================================================
// Constructor using 2 IOParameter objects as input.
IOParameter::IOParameter( const IOParameter& Prefix, const IOParameter& Postfix)
{
size = Prefix.size + Postfix.size - 1;
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, Prefix.pBuf);
strcat(pBuf, Postfix.pBuf);
}
//===========================================================================
// Subscript, etc.
//===========================================================================
char IOParameter::operator [] (int Index)
{
char c;
if (Index > size)
c = '\0';
else
c = pBuf[Index];
return c;
}
//===========================================================================
// Assignment.
//===========================================================================
IOParameter IOParameter::operator = ( const IOParameter &Other )
{
if(pBuf)
delete [] pBuf;
size = Other.size;
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, Other.pBuf);
return *this;
}
//===========================================================================
IOParameter IOParameter::operator = ( const char *str )
{
size = strlen(str) +1;
if (pBuf)
delete [] pBuf;
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, str);
return *this;
}
//===========================================================================
// I/O operators.
//===========================================================================
ostream &operator << ( ostream &Stream, const IOParameter &Other )
{
Stream << Other.pBuf;
return Stream;
}
//===========================================================================
istream &operator >> ( istream &Stream, IOParameter &Other )
{
const int buflen = 255; // Arbitrary size, change if needed.
char t[buflen]; // temp string...
int len;
for (len=0; len<buflen; len++)
{
Stream.get(t[len]);
if (t[len] == '\n') // Newline character
break;
if (t[len] == '\b') // Backspace character
{
if(len)
{
len--;
}
}
}
t[len] = '\0';
len++;
if(Other.pBuf)
delete [] Other.pBuf;
if (! (Other.pBuf = new char[len]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
Other.size = len;
strcpy(Other.pBuf, t);
return Stream;
} // END istream &operator >>
//===========================================================================
// Concatenate.
//===========================================================================
IOParameter IOParameter::operator + ( const IOParameter &Other ) // Cat 2 IOParameter objects.
{
return IOParameter( *this, Other );
}
//===========================================================================
IOParameter IOParameter::operator + ( const char *str ) // Cat IOParameter and string.
{
return IOParameter( *this, IOParameter(str) );
}
//===========================================================================
IOParameter operator + ( char *str, const IOParameter &Other ) // Cat string with IOParameter.
{
return IOParameter( IOParameter(str), Other );
}
//===========================================================================
IOParameter& IOParameter::operator << ( const IOParameter &Other ) // Cat 2 IOParameter objects.
{
IOParameter TempString(*this);
size = TempString.size + Other.size - 1;
if (pBuf)
delete [] pBuf;
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, TempString.pBuf);
strcat(pBuf, Other.pBuf);
return *this;
}
//===========================================================================
IOParameter& IOParameter::operator << ( const char *str ) // Cat IOParameter and string.
{
IOParameter TempString(*this);
IOParameter Other(str);
size = TempString.size + Other.size - 1;
if (pBuf)
delete [] pBuf;
if(! (pBuf = new char[size]) )
{
cout << "IOParameter: Allocation Error!!!" << endl;
exit(1);
}
strcpy(pBuf, TempString.pBuf);
strcat(pBuf, Other.pBuf);
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -