1.cpp
来自「c++的标准模板STL操作」· C++ 代码 · 共 49 行
CPP
49 行
#include <iostream>
#include <string>
#include <list>
using namespace std;
int main (void)
{
#define OK 0
#define INFO 1
#define WARNING 2
int return_code;
list <string> InfoMessages;
list <string> WarningMessages;
// during a program these messages are loaded at various points
InfoMessages.push_back("Info: Program started");
// do work...
WarningMessages.push_back("Warning: No Customer records have been found");
// do work...
return_code = OK;
if (!InfoMessages.empty()) { // there were info messages
InfoMessages.push_front("Informational Messages:");
// ... print the info messages list, we'll see how later
return_code = INFO;
}
if (!WarningMessages.empty()) { // there were warning messages
WarningMessages.push_front("Warning Messages:");
// ... print the warning messages list, we'll see how later
return_code = WARNING;
}
// If there were no messages say so.
if (InfoMessages.empty() && WarningMessages.empty()) {
cout << "There were no messages " << endl;
}
for(list < string > ::const_iterator it =InfoMessages.begin();it!=InfoMessages.end();++it)
{
cout<<(*it)<<endl;
}
return return_code;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?