64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
const string StdLibKey[] = {
"abort", "ios_base", "accumulate", "isalpha", "allocator", "islower", "auto_ptr", "ispunct", "back_inserter"
"isspace", "bad_alloc", "istream", "bad_cast", "istream_iterator", "bind2nd", "istringstream", "bitset"
"isupper", "boolalpha", "left", "cerr", "less_equal", "cin", "list", "copy", "logic_error", "count", "lower_bound"
"count_if", "make_pair", "cout", "map", "dec", "max", "deque", "min", "endl", "multimap", "ends", "multiset", "equal_range"
"negate", "exception", "noboolalpha", "fill", "noshowbase", "fill_n", "noshowpoint", "find", "noskipws", "find_end"
"not1", "find_first_of", "nounitbuf", "fixed", "nouppercase", "flush", "nth_element", "for_each", "oct", "front_inserter"
"of", "stream", "fstream", "ostream", "getline", "ostream_iterator", "hex", "ostringstream", "ifstream", "out_of_range"
"inner_product", "pair", "inserter", "partial_sort", "internal", "plus", "priority_queue", "sqrt", "ptrdiff_t"
"stable_sort", "queue", "stack", "range_error", "strcmp", "replace", "strcpy", "replace_copy", "string", "reverse_iterator"
"stringstream", "right", "strlen", "runtime_error", "strncpy", "scientific", "terminate", "set", "tolower", "set_difference"
"toupper", "set_intersection", "type_info", "set_union", "unexpected", "setfill", "uninitialized_copy", "setprecision"
"unitbuf", "setw", "unique", "showbase", "unique_copy", "showpoint", "upper_bound", "size_t", "uppercase", "skipws"
"vector", "sort"
};
const int StdLibKey_size = sizeof(StdLibKey) / sizeof(*StdLibKey) ;
int main()
{
string input;
cout << "请输入C++ namespace 标准库关键字:" << endl;
cin >> input;
for (int i = 0 ; i != StdLibKey_size ; ++i) {
if (input == StdLibKey[i]) {
cout << input << " 是标准库关键字";
break;
}
}
return 0;
}
while()
{
//每循环一次读取单词库中的下一个单词,代码自己写
if(输入的单词 == 单词库中的单词)
{
//执行让蜂鸣器报警的代码
break;
}
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool findStringInVec(string str , vector<string> &StdLibKey)
{
for (auto it = StdLibKey.begin() ;it != StdLibKey.end() ; ++it) {
if (str == *it)
return true;
}
return false;
}
int main()
{
vector<string> StdLibKey = {
"abort", "ios_base", "accumulate", "isalpha", "allocator", "islower", "auto_ptr", "ispunct", "back_inserter"
"isspace", "bad_alloc", "istream", "bad_cast", "istream_iterator", "bind2nd", "istringstream", "bitset"
"isupper", "boolalpha", "left", "cerr", "less_equal", "cin", "list", "copy", "logic_error", "count", "lower_bound"
"count_if", "make_pair", "cout", "map", "dec", "max", "deque", "min", "endl", "multimap", "ends", "multiset", "equal_range"
"negate", "exception", "noboolalpha", "fill", "noshowbase", "fill_n", "noshowpoint", "find", "noskipws", "find_end"
"not1", "find_first_of", "nounitbuf", "fixed", "nouppercase", "flush", "nth_element", "for_each", "oct", "front_inserter"
"of", "stream", "fstream", "ostream", "getline", "ostream_iterator", "hex", "ostringstream", "ifstream", "out_of_range"
"inner_product", "pair", "inserter", "partial_sort", "internal", "plus", "priority_queue", "sqrt", "ptrdiff_t"
"stable_sort", "queue", "stack", "range_error", "strcmp", "replace", "strcpy", "replace_copy", "string", "reverse_iterator"
"stringstream", "right", "strlen", "runtime_error", "strncpy", "scientific", "terminate", "set", "tolower", "set_difference"
"toupper", "set_intersection", "type_info", "set_union", "unexpected", "setfill", "uninitialized_copy", "setprecision"
"unitbuf", "setw", "unique", "showbase", "unique_copy", "showpoint", "upper_bound", "size_t", "uppercase", "skipws"
"vector", "sort"
};
string input;
cout << "请输入C++ namespace 标准库关键字(输入quit退出):" << endl;
while (cin >> input) {
if (findStringInVec(input, StdLibKey))
cout << input << " 是标准库关键字\n";
else
cout << input << " NO!\n";
if (input == string("quit")) {
return -1;
}
}
return 0;
}