数组使用find查询用法
#include "stdafx.h"
#include <string>
#include <list>
#include <algorithm>
#include <iostream>
using namespace std;
class Student
{
public:
Student(){}
Student(string name,string sex,int age,string number);
int getAge(){return _age;}
string getNumber(){return _number;}
bool operator==(const string&str)//重载操作符
{
return str==_number;
}
bool operator==(const int&stemp)
{
return stemp==_age;
}
private:
string _name;
string _sex;
int _age;
string _number;
};
Student::Student(string name,string sex,int age,string number)
{
_name=name;
_sex=sex;
_age=age;
_number=number;
}
int _tmain(int argc, _TCHAR* argv[])
{
Student st[5]={
Student("la","男",12,"122"),
Student("小林","男",13,"123"),
Student("小林","男",14,"124")
};
string strnum;
cout<<"enter number:";
cin>>strnum;
Student *present=find(st,st+4,strnum);
cout<<"这个学生的学号是:"<<present->getNumber()<<endl;
int age;
cout<<"enter age: ";
cin>>age;
Student *pre=find(st,st+4,age);
cout<<"这个学生的年龄是:"<<pre->getAge();
getchar();
getchar();
return 0;
}
数组使用find查询用法的更多相关文章
- JavaScript中常见的数组操作函数及用法
JavaScript中常见的数组操作函数及用法 昨天写了个帖子,汇总了下常见的JavaScript中的字符串操作函数及用法.今天正好有时间,也去把JavaScript中常见的数组操作函数及用法总结一下 ...
- 【shell】构造并遍历二位数组的一种用法
参考shell数组的部分操作用法,实现了构造和遍历二维数组的一种方式,具体如下: #数组元素以空格分割 sites=("www.a.com www.b.com www.c.com www.d ...
- JS中Array数组的三大属性用法
原文:JS中Array数组的三大属性用法 Array数组主要有3大属性,它们分别是length属性.prototype属性和constructor属性. JS操作Array数组的方法及属性 本文总结了 ...
- Ruby数组(1):基本用法
数组 Ruby中的数组是一个容器,数组中的每个元素都是一个对象的引用. 注意,Array类中包含了Enumerable模块,所以Enumerable中的方法也都能使用,例如Enumerable中的re ...
- Hibernate中Restrictions查询用法(转)
Restrictions查询用法 HQL运算符 QBC运算符 含义 = Restrictions.eq() 等于equal <> Restrictions.ne() 不等于not equa ...
- mysql union 和 left join 结合查询用法
union 和 left join 结合查询用法 SELECT u.nickname,z.group_comming_type,z.id,z.user_id,z.title,z.create_time ...
- hashSet的底层是数组,其查询效率非常高
如果偷懒,没有设定equals(),就会造成返回hashCode虽然结果相同,但在程序执行的过程中会多次地调用equals(),从而影响程序执行的效率. 我们要保证相同对象的返回的hashCode一定 ...
- Java-MyBatis-杂项:MyBatis根据数组、集合查询
ylbtech-Java-MyBatis-杂项:MyBatis根据数组.集合查询 1.返回顶部 1. foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合.foreach元素的 ...
- mysql子查询用法
mysql子查询用法 1 可以当值来用<pre>select id from hcyuyin_share where id=(select id from hcyuyin_share li ...
随机推荐
- IIS、SQL SERVER和VS的安装顺序
正确安装顺序:先安装IIS,再安装SQL SERVER,最后安装VS. 如果先安装VS后安装的IIS,则需要找到对应的.net framework目录下,执行aspnet_regiis.exe,重新注 ...
- 出色的 JavaScript API 设计秘诀
设计是一个很普遍的概念,一般是可以理解为为即将做的某件事先形成一个计划或框架. (牛津英语词典)中,设计是一种将艺术,体系,硬件或者更多的东西编织到一块的主线.软件设计,特别是作为软件设计的次类的AP ...
- 关于spring mvc MaxUploadSizeExceededException 死循环解决方案
当看到这文章的时候相信你现在应该遇到这样的问题了,我也是自己遇到了后来找到解决方案了记录下来,如果下次遇到就可以直接解决了. 至于为什么会出现这样的情况,可以看这篇文章:https://bz.apac ...
- java并发编程:如何创建线程
原文:http://www.cnblogs.com/dolphin0520/p/3913517.html 一.Java中关于应用程序和进程相关的概念 在Java中,一个应用程序对应着一个JVM实例(也 ...
- JS中的forEach、$.each、map方法
forEach是ECMA5中Array新方法中最基本的一个,就是遍历,循环.例如下面这个例子: [1, 2 ,3, 4].forEach(alert); 等同于下面这个for循环 var array ...
- quartz2D简单使用
quartz2D绘图 1:上下文:context,这个翻译不好理解,其实翻译环境更好一点,就是给了你一个画板,你看不到而已 在: CGContextRef ctx = UIGraphicsGetCur ...
- android开发 textview根据字数长度自动调整字体大小
需求:根据输入的值实时显示到textview中预览,但是字体大小是要自动适配的 网上有一个代码,但是在我这里不能用,注意方法:refitText 注释掉的是之前的代码 import com.cars ...
- 【Merge Sorted Array】cpp
题目: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Not ...
- 学习Linux第五天
1.VIM编辑器 3种模式: Command Model , Insert Model , Last line Model 安装vim: sudo apt-get install vim 如果提示出错 ...
- 0910 noip模拟
教师节快乐: T1:勇士闯魔塔,是一道很裸的莫队题目,但在老师的催促下,出题人@syq同学修改了第一题,使之成了一道送分题,全暴力水过: T2:第二题是一道预处理+分组背包,考试中,忘了分组背包怎么敲 ...