////////////////////////////////////////
#include
#include
// Function prototype.
void ErrorMsg();
void ErrorMsg();
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
// Call the function.
ErrorMsg();
// The main() function.
////////////////////////////////////////
int main()
{
// Call the function.
ErrorMsg();
return 0;
}
}
////////////////////////////////////////
// Display an error message.
////////////////////////////////////////
void ErrorMsg()
{
std::cout << "\aError!";
}
// Display an error message.
////////////////////////////////////////
void ErrorMsg()
{
std::cout << "\aError!";
}
////////////////////////////////////////
#include
// Prototype
void show(int = 1, float = 2.3, long = 4);
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
main()
{
show(); // all three arguments default
show(5); // provide 1st argument
show(6, 7.8); // provide 1st two
show(9, 10.11, 12L); // provide all three arguments
}
////////////////////////////////////////
// Display results of default arguments.
////////////////////////////////////////
void show(int first, float second, long third)
{
std::cout << " first = " << first;
std::cout << ", second = " << second;
std::cout << ", third = " << third << std::endl;
}
#include
#include
////////////////////////////////////////
// An inline function.
////////////////////////////////////////
inline void error_message(char* s)
{
std::cout << '\a' << s;
std::exit(1);
}
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
main()
{
error_message("You called?");
}
////////////////////////////////////////
#include
////////////////////////////////////////
// The first version of string_copy().
////////////////////////////////////////
void string_copy(char *dest, const char* src)
{
while((*dest++ = *src++) != '\0')
;
}
////////////////////////////////////////
// The second version of string_copy().
////////////////////////////////////////
void string_copy(char* dest, const char* src, int len)
{
while (len && (*dest++ = *src++) != '\0')
--len;
while (len--)
*dest++ = '\0';
}
char misspiggy[20], kermit[20];
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
main()
{
string_copy(misspiggy, "Miss Piggy");
string_copy(kermit,
"Kermit, the file transfer protocol", 6);
std::cout << kermit << " and " << misspiggy;
}
////////////////////////////////////////
#include
#include
////////////////////////////////////////
// The first version of display_time().
////////////////////////////////////////
void display_time(const struct std::tm* tim)
{
std::cout << "1. It is now " << std::asctime(tim);
}
////////////////////////////////////////
// The second version of display_time().
////////////////////////////////////////
void display_time(time_t* tim)
{
std::cout << "2. It is now " << std::ctime(tim);
}
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
std::time_t tim = std::time(0);
struct std::tm* ltim = std::localtime(&tim);
display_time(ltim);
display_time(&tim);
return 0;
}
More Articles …
Page 18 of 21