找到 34423 篇文章 关于编程

C++ STL 中的 lldiv() 函数

Jennifer Nicholas
更新于 2019年7月30日 22:30:25

92 次浏览

C++ STL 中的 lldiv() 函数给出两个数相除的商和余数的结果。算法:开始,输入两个长整型数字。调用 lldiv() 函数。打印商和余数。结束。示例代码:`#include ` `#include ` `using namespace std;` `int main() {` ` long long q = 500LL;` ` long long r = 25LL;` ` lldiv_t res = lldiv(q, r);` ` cout…

C++ STL 中的 iswalpha() 函数

Nitya Raut
更新于 2019年7月30日 22:30:25

95 次浏览

C++ STL 中的 iswalpha() 函数用于检查给定的宽字符是否为字母。算法:开始,初始化字符串。调用函数 iswalpha(str) 检查其是否包含字母。如果包含字母,则返回相应的值,否则返回零。结束。示例代码:`#include ` `#include ` `#include ` `#include ` `using namespace std;` `int main() {` ` setlocale(LC_ALL, "ab1234");` ` wchar_t s[] = L"a%$^^&)";` ` bool flag = 0;` ` for (int i=0; i…

C++ STL 中的 iswalnum() 函数

Vrundesha Joshi
更新于 2019年7月30日 22:30:25

149 次浏览

C++ STL 中的 iswalnum() 函数检查给定的宽字符是否为字母数字字符,即数字 (0-9)、大写字母 (A-Z)、小写字母 (a-z) 或任何字母数字字符。算法:开始,初始化字符。调用函数 iswalnum(c1) 检查它是否为字母数字字符。如果是字母数字字符,则返回相应的值,否则返回零。结束。示例代码:`#include ` `#include ` `using namespace std;` `int main() {` ` wchar_t c1 = '/';` ` wchar_t c2 = 'a';` ` if (iswalnum(c1))` ` wcout…

C++ STL 集合中的插入和删除

Jennifer Nicholas
更新于 2019年7月30日 22:30:25

901 次浏览

插入:STL 集合中的插入可以通过 insert() 和 emplace() 操作完成。Insert():Insert() 用于向集合插入元素。插入操作需要一个对象的引用。使用的函数列表:st.size() = 返回集合的大小。st.insert() = 用于向集合插入元素。示例代码:`#include ` `#include ` `#include ` `#include ` `using namespace std;` `int main() {` ` set st;` ` set::iterator it;` ` int c, i;` ` while (1) {` ` cout…

如何从具有特定值的 C++ STL 向量中删除项目?

Nitya Raut
更新于 2019年7月30日 22:30:25

613 次浏览

Erase 函数用于从具有特定值的 C++ STL 向量中删除项目。算法:开始,声明向量 v 和向量迭代器 it。初始化向量。使用 Erase() 函数从末尾删除项目。打印剩余元素。结束。示例代码:`#include ` `#include ` `using namespace std;` `int main() {` ` vector v{ 6,7,8,9,10};` ` vector::iterator it;` ` it = v.end();` ` it--;` ` v.erase(it);` ` for (auto it = v.begin(); it != v.end(); ++it)` ` cout…

C++ STL 中的 emplace 与 insert

Vrundesha Joshi
更新于 2019年7月30日 22:30:25

1K+ 次浏览

emplace 操作避免了不必要的对象复制,并且比 insert 操作更有效地进行插入。Insert 操作需要一个对象的引用。算法:开始,声明集合。使用 emplace() 插入对。使用 insert() 通过使用 emplace() 插入对。打印集合。结束。示例代码:`#include ` `#include ` `using namespace std;` `int main() {` ` set s;` ` s.emplace(7, 'a');` ` s.insert(make_pair(6, 'b'));` ` for (auto it = s.begin(); it != s.end(); ++it)` ` cout…

C++ STL 中 Map 和 Multimap 的降序

Jennifer Nicholas
更新于 2019年7月30日 22:30:25

3K+ 次浏览

通常,map 和 multimap 的默认行为是按升序存储元素。但是,我们可以使用 greater 函数按降序存储元素。降序 map:这里使用的函数 - m::find() – 如果找到,则返回指向 map 中键值为“b”的元素的迭代器,否则返回指向末尾的迭代器。m::erase() – 从 map 中删除键值。m::equal_range() – 返回迭代器对。该对指的是包含容器中所有具有与键等效键的元素的范围的边界。m insert() ... 阅读更多

C++ 程序:在 STL 中实现向量

Nitya Raut
更新于 2019年7月30日 22:30:25

421 次浏览

向量能够像动态数组一样自动调整自身大小,当插入或删除元素时,容器会自动处理其存储。向量元素放置在连续的存储空间中,以便可以使用迭代器访问和遍历它们。可以在向量的开头、中间或结尾插入或删除数据。函数和说明:这里使用的函数列表:v.size() = 返回向量的长度。v.push_back() = 用于从末尾向向量插入元素。v.pop_back() = 从后面弹出向量中的值。v.capacity() = ... 阅读更多

C++ 程序:在 STL 中实现栈

Vrundesha Joshi
更新于 2019年7月30日 22:30:25

979 次浏览

栈是一种线性数据结构,它遵循执行操作的特定顺序。顺序可以是 FILO(先进先出)或 LIFO(后进先出)算法:开始,声明栈向量。根据选择获取输入。在 switch 操作中调用函数:s.size() = 返回栈的大小。s.push() = 用于向栈插入元素。s.pop() = 弹出栈中的值。s.top() = 返回... 阅读更多

C++ 程序:在 STL 中实现排序容器

Jennifer Nicholas
更新于 2019年7月30日 22:30:25

135 次浏览

在这个 C++ 程序中,我们在 STL 中实现了排序容器。函数和说明:这里使用的函数:l.push_back() = 用于将元素从前面推入列表。l.sort() = 对列表的元素进行排序。其中 l 是一个列表对象。示例代码:`#include ` `#include ` `#include ` `#include ` `using namespace std;` `int main() {` ` list l;` ` list::iterator it;` ` int c, i;` ` while (1) {` ` cout…

广告
© . All rights reserved.