当前位置:文档之家› C++string类标准库常用函数

C++string类标准库常用函数

C++string类标准库常用函数
C++string类标准库常用函数

C++ string类标准库常用函数

[string类的构造函数]

string(const char *s); //用c字符串s初始化

string(int n,char c); //用n个字符c初始化

[string类的字符操作]

const char &operator[](int n) const;

const char &at(int n) const;

char &operator[](int n);

char &at(int n);

operator[]和at()均返回当前字符串中第n个字符的位置,但at函数提供范围检查,当越界时会抛出out_of_range 异常,下标运算符[]不提供检查访问。

const char *data() const; //返回一个非null终止的c字符数组

const char *c_str() const; //返回一个以null终止的c字符串

int copy(char *s, int n, int pos = 0) const;//把当前串中以pos开始的n个字符拷贝到以s为起始位置的字符数组中,返回实际拷贝的数目

[string的特性描述]

int capacity() const; //返回当前容量(即string中不必增加内存即可存放的元素个数)

int max_size() const; //返回string对象中可存放的最大字符串的长度

int size() const; //返回当前字符串的大小

int length() const; //返回当前字符串的长度

bool empty() const; //当前字符串是否为空

void resize(int len,char c); //把字符串当前大小置为len,并用字符c填充不足的部分

[string类的输入输出操作]

string类重载运算符operator>>用于输入,同样重载运算符operator<<用于输出操作。

函数getline(istream &in,string &s);用于从输入流in中读取字符串到s中,以换行符'\n'分开。

[string的赋值]

string &operator=(const string &s); //把字符串s赋给当前字符串

string &assign(const char *s); //用c类型字符串s赋值

string &assign(const char *s,int n); //用c字符串s开始的n个字符赋值

string &assign(const string &s); //把字符串s赋给当前字符串

string &assign(int n,char c); //用n个字符c赋值给当前字符串

string &assign(const string &s,int start,int n);//把s中从start开始的n个字符赋给当前字符串string &assign(const_iterator first,const_iterator last);//把迭代器first和last之间的部分赋给字符串

[string的连接]

string &operator+=(const string &s); //把字符串s连接到当前字符串的结尾

string &append(const char *s); //把c类型字符串s连接到当前字符串结尾

string &append(const char *s,int n); //把c类型字符串s的前n个字符连接到当前字符串结尾

string &append(const string &s); //同operator+=()

string &append(const string &s,int pos,int n); //把字符串s中从pos开始的n个字符连接到当前字符串的结尾

string &append(int n,char c); //在当前字符串结尾添加n个字符c

string &append(const_iterator first,const_iterator last); //把迭代器first和last之间的部分连接到当前字符串的结尾

[string的比较]

bool operator==(const string &s1,const string &s2)const; //比较两个字符串是否相等

运算符">","<",">=","<=","!="均被重载用于字符串的比较;

int compare(const string &s) const; //比较当前字符串和s的大小

int compare(int pos, int n,const string &s)const; //比较当前字符串从pos开始的n个字符组成的字符串与s的大小

int compare(int pos, int n,const string &s,int pos2,int n2)const; //比较当前字符串从pos开始的n个字符组成的字符串与s中pos2开始的n2个字符组成的字符串的大小

int compare(const char *s) const;

int compare(int pos, int n,const char *s) const;

int compare(int pos, int n,const char *s, int pos2) const;

compare函数在>时返回1,<时返回-1,==时返回0。

[string的子串]

string substr(int pos = 0,int n = npos) const; //返回pos开始的n个字符组成的字符串

[string的交换]

void swap(string &s2); //交换当前字符串与s2的值

[string类的查找函数]

int find(char c, int pos = 0) const; //从pos开始查找字符c在当前字符串的位置

int find(const char *s, int pos = 0) const; //从pos开始查找字符串s在当前串中的位置

int find(const char *s, int pos, int n) const;//从pos开始查找字符串s中前n个字符在当前串中的位置int find(const string &s, int pos = 0) const;//从pos开始查找字符串s在当前串中的位置

//查找成功时返回所在位置,失败返回string::npos的值

int rfind(char c, int pos = npos) const; //从pos开始从后向前查找字符c在当前串中的位置

int rfind(const char *s, int pos = npos) const;

int rfind(const char *s, int pos, int n = npos) const;

int rfind(const string &s,int pos = npos) const;

//从pos开始从后向前查找字符串s中前n个字符组成的字符串在当前串中的位置,成功返回所在位置,失败时返回string::npos

int find_first_of(char c, int pos = 0) const; //从pos开始查找字符c第一次出现的位置

int find_first_of(const char *s, int pos = 0) const;

int find_first_of(const char *s, int pos, int n) const;

int find_first_of(const string &s,int pos = 0) const;

//从pos开始查找当前串中第一个在s的前n个字符组成的数组里的字符的位置。查找失败返回string::npos

int find_first_not_of(char c, int pos = 0) const;

int find_first_not_of(const char *s, int pos = 0) const;

int find_first_not_of(const char *s, int pos,int n) const;

int find_first_not_of(const string &s,int pos = 0) const;

//从当前串中查找第一个不在串s中的字符出现的位置,失败返回string::npos

int find_last_of(char c, int pos = npos) const;

int find_last_of(const char *s, int pos = npos) const;

int find_last_of(const char *s, int pos, int n = npos) const;

int find_last_of(const string &s,int pos = npos) const;

int find_last_not_of(char c, int pos = npos) const;

int find_last_not_of(const char *s, int pos = npos) const;

int find_last_not_of(const char *s, int pos, int n) const;

int find_last_not_of(const string &s,int pos = npos) const;

//find_last_of和find_last_not_of是从后向前查找

[string类的替换函数]

string &replace(int p0, int n0,const char *s);//删除从p0开始的n0个字符,然后在p0处插入串s string &replace(int p0, int n0,const char *s, int n);//删除p0开始的n0个字符,然后在p0处插入字符串s的前n个字符

string &replace(int p0, int n0,const string &s);//删除从p0开始的n0个字符,然后在p0处插入串s string &replace(int p0, int n0,const string &s, int pos, int n);//删除p0开始的n0个字符,然后在p0处插入串s中从pos开始的n个字符

string &replace(int p0, int n0,int n, char c);//删除p0开始的n0个字符,然后在p0处插入n个字符c string &replace(iterator first0, iterator last0,const char *s);//把[first0,last0)之间的部分替换为字符串s

string &replace(iterator first0, iterator last0,const char *s, int n);//把[first0,last0)之间的部分替换为s的前n个字符

string &replace(iterator first0, iterator last0,const string &s);//把[first0,last0)之间的部分替换为串s

string &replace(iterator first0, iterator last0,int n, char c);//把[first0,last0)之间的部分替换为n个字符c

string &replace(iterator first0, iterator last0,const_iterator first, const_iterator last); //把[first0,last0)之间的部分替换成[first,last)之间的字符串

[string类的插入函数]

string &insert(int p0, const char *s);

string &insert(int p0, const char *s, int n);

string &insert(int p0,const string &s);

string &insert(int p0,const string &s, int pos, int n);

//前4个函数在p0位置插入字符串s中pos开始的前n个字符

string &insert(int p0, int n, char c); //此函数在p0处插入n个字符c

iterator insert(iterator it, char c); //在it处插入字符c,返回插入后迭代器的位置

void insert(iterator it, const_iterator first, const_iterator last);//在it处插入[first,last)之间的字符

void insert(iterator it, int n, char c); //在it处插入n个字符c

[string类的删除函数]

iterator erase(iterator first, iterator last);//删除[first,last)之间的所有字符,返回删除后迭代器的位置

iterator erase(iterator it); //删除it指向的字符,返回删除后迭代器的位置

string &erase(int pos = 0, int n = npos); //删除pos开始的n个字符,返回修改后的字符串

[string类的迭代器处理]

string类提供了向前和向后遍历的迭代器iterator,迭代器提供了访问各个字符的语法,类似于指针操作,迭代器不检查范围。用string::iterator或string::const_iterator声明迭代器变量,const_iterator不允许改变迭代的内容。常用迭代器函数有:

const_iterator begin()const;

iterator begin(); //返回string的起始位置

const_iterator end()const;

iterator end(); //返回string的最后一个字符后面的位置

const_iterator rbegin()const;

iterator rbegin(); //返回string的最后一个字符的位置

const_iterator rend()const;

iterator rend(); //返回string第一个字符位置的前面

rbegin()和rend()用于从后向前的迭代访问,它们通过设置迭代器string::reverse_iterator,string::const_reverse_iterator实现。

C语言标准库函数2012

常用C语言标准库函数2012 C语言编译系统提供了众多的预定义库函数和宏。用户在编写程序时,可以直接调用这些库函数和宏。这里选择了初学者常用的一些库函数,简单介绍了各函数的用法和所在的头文件。 1.测试函数 Isalnum 原型:int isalnum(int c) 功能:测试参数c是否为字母或数字:是则返回非零;否则返回零 头文件:ctype.h Isapha 原型:int isapha(int c) 功能:测试参数c是否为字母:是则返回非零;否则返回零 头文件:ctype.h Isascii 原型:int isascii(int c) 功能:测试参数c是否为ASCII码(0x00~0x7F):是则返回非零;否则返回零 头文件:ctype.h Iscntrl 原型:int iscntrl(int c) 功能:测试参数c是否为控制字符(0x00~0x1F、0x7F):是则返回非零;否则返回零 头文件:ctype.h Isdigit 原型:int isdigit(int c) 功能:测试参数c是否为数字:是则返回非零;否则返回零。 头文件:ctype.h Isgraph 原型:int isgraph(int c) 功能:测试参数c是否为可打印字符(0x21~0x7E):是则返回非零;否则返回零头文件:ctype.h Islower 原型:int islower(int c) 功能:测试参数c是否为小写字母:是则返回非零;否则返回零 头文件:ctype.h

Isprint 原型:int isprint(int c) 功能:测试参数c是否为可打印字符(含空格符0x20~0x7E):是则返回非零;否则返回零 头文件:ctype.h Ispunct 原型:int ispunct(int c) 功能:测试参数c是否为标点符号:是则返回非零;否则返回零 头文件:ctype.h Isupper 原型:int isupper(inr c) 功能:测试参数c是否为大写字母:是则返回非零;否则返回零 Isxdigit 原型:int isxdigit(int c) 功能:测试参数c是否为十六进制数:是则返回非零;否则返回零 2.数学函数 abs 原型:int abs(int i) 功能:返回整数型参数i的绝对值 头文件:stdlib.h,math.h acos 原型:double acos(double x) 功能:返回双精度参数x的反余弦三角函数值 头文件:math.h asin 原型:double asin(double x) 功能:返回双精度参数x的反正弦三角函数值 头文件:math.h atan 原型:double atan(double x) 功能:返回双精度参数的反正切三角函数值 头文件:math.h atan2 原型:double atan2(double y,double x) 功能:返回双精度参数y和x由式y/x所计算的反正切三角函数值 头文件:math.h cabs

STRING类函数用法总结3

C++中的string类 前言:string的角色 1string使用 1.1充分使用string操作符 1.2眼花缭乱的string find函数 1.3string insert,replace,erase2string和C风格字符串 3string和Charactor Traits 4string建议 5小结 6附录前言:string的角色 C++语言是个十分优秀的语言,但优秀并不表示完美。还是有许多人不愿意使用C或者C++,为什么?原因众多,其中之一就是C/C++的文本处理功能太麻烦,用起来很不方便。以前没有接触过其他语言时,每当别人这么说,我总是不屑一顾,认为他们根本就没有领会C++的精华,或者不太懂C++,现在我接触perl,php,和Shell脚本以后,开始理解了以前为什么有人说C++文本处理不方便了。 举例来说,如果文本格式是:用户名电话号码,文件名name.txt Tom23245332 Jenny22231231 Heny22183942 Tom23245332 ... 现在我们需要对用户名排序,且只输出不同的姓名。 那么在shell编程中,可以这样用: awk'{print$1}'name.txt|sort|uniq 简单吧? 如果使用C/C++就麻烦了,他需要做以下工作: 先打开文件,检测文件是否打开,如果失败,则退出。 声明一个足够大得二维字符数组或者一个字符指针数组 读入一行到字符空间 然后分析一行的结构,找到空格,存入字符数组中。 关闭文件 写一个排序函数,或者使用写一个比较函数,使用qsort排序 遍历数组,比较是否有相同的,如果有,则要删除,copy... 输出信息 你可以用C++或者C语言去实现这个流程。如果一个人的主要工作就是处理这种

C++string类型总结

对C++中string类型的总结 string类对象的构造 简化构造函数原型如下(注意,为了简便,把模板中最后一个默认参数省略了): 1: explicit basic_string(); 2: string(const char *s); 3: string(const char *s, size_type n); 4: string(const string& str); 5: string(const string& str, size_type pos, size_type n); 6: string(size_type n, E c); 7: string(const_iterator first, const_iterator last); string对象的操作 字符串比较 支持六种关系运算符(==、!=、>、>=、<、<=),其采用字典排序策略(与C中字符串比较策略完全一样)。这六个关系运算符是非成员的重载运算符。而这些 运算符都支持三种操作数组合:string op string、string op const char*、cons t char* op string(其中op是前面六种关系运算符中任意一种)。解释:提供运算 符的三种重载版本主要是从效率角度考虑的,其避免了临时string对象的产生。 另外,string类还提供了各种重载版本的成员函数compare来比较,简化函数原型为: 1: int compare(const string& str) const; 2: int compare(size_type p0, size_type n0, const string& str); 3: int compare(size_type p0, size_type n0, const string& str, si ze_type pos, size_type n); 4: int compare(const char* s) const; 5: int compare(size_type p0, size_type n0, const char* s) const; 6: int compare(size_type p0, size_type n0, const char* s, size_t ype n) const; 返回值:如果调用该函数的对象的比较序列小于操作数比较序列,则返回负数; 若相等,则返回0;否则,返回正数。

C++string类标准库常用函数

C++ string类标准库常用函数 [string类的构造函数] string(const char *s); //用c字符串s初始化 string(int n,char c); //用n个字符c初始化 [string类的字符操作] const char &operator[](int n) const; const char &at(int n) const; char &operator[](int n); char &at(int n); operator[]和at()均返回当前字符串中第n个字符的位置,但at函数提供范围检查,当越界时会抛出out_of_range 异常,下标运算符[]不提供检查访问。 const char *data() const; //返回一个非null终止的c字符数组 const char *c_str() const; //返回一个以null终止的c字符串 int copy(char *s, int n, int pos = 0) const;//把当前串中以pos开始的n个字符拷贝到以s为起始位置的字符数组中,返回实际拷贝的数目 [string的特性描述] int capacity() const; //返回当前容量(即string中不必增加内存即可存放的元素个数) int max_size() const; //返回string对象中可存放的最大字符串的长度 int size() const; //返回当前字符串的大小 int length() const; //返回当前字符串的长度 bool empty() const; //当前字符串是否为空 void resize(int len,char c); //把字符串当前大小置为len,并用字符c填充不足的部分 [string类的输入输出操作] string类重载运算符operator>>用于输入,同样重载运算符operator<<用于输出操作。 函数getline(istream &in,string &s);用于从输入流in中读取字符串到s中,以换行符'\n'分开。 [string的赋值] string &operator=(const string &s); //把字符串s赋给当前字符串 string &assign(const char *s); //用c类型字符串s赋值 string &assign(const char *s,int n); //用c字符串s开始的n个字符赋值 string &assign(const string &s); //把字符串s赋给当前字符串 string &assign(int n,char c); //用n个字符c赋值给当前字符串 string &assign(const string &s,int start,int n);//把s中从start开始的n个字符赋给当前字符串string &assign(const_iterator first,const_iterator last);//把迭代器first和last之间的部分赋给字符串 [string的连接] string &operator+=(const string &s); //把字符串s连接到当前字符串的结尾 string &append(const char *s); //把c类型字符串s连接到当前字符串结尾 string &append(const char *s,int n); //把c类型字符串s的前n个字符连接到当前字符串结尾 string &append(const string &s); //同operator+=() string &append(const string &s,int pos,int n); //把字符串s中从pos开始的n个字符连接到当前字符串的结尾 string &append(int n,char c); //在当前字符串结尾添加n个字符c string &append(const_iterator first,const_iterator last); //把迭代器first和last之间的部分连接到当前字符串的结尾

CPPstring类常用函数

C++string类常用函数 string类的构造函数: string(const char *s); //用c字符串s初始化 string(int n,char c); //用n个字符c初始化 此外,string类还支持默认构造函数和复制构造函数,如string s1;string s2="hello";都是正确的写法。当构造的string太长而无法表达时会抛出length_error异常 string类的字符操作: const char &operator[](int n)const; const char &at(int n)const; char &operator[](int n); char &at(int n); operator[]和at()均返回当前字符串中第n个字符的位置,但at函数提供范围检查,当越界时会抛出out_of_range异常,下标运算符[]不提供检查访问。 const char *data()const;//返回一个非null终止的c字符数组 const char *c_str()const;//返回一个以null终止的c字符串 int copy(char *s, int n, int pos = 0) const;//把当前串中以pos开始的n个字符拷贝到以s为起始位置的字符数组中,返回实际拷贝的数目 string的特性描述: int capacity()const; //返回当前容量(即string中不必增加内存即可存放的元素个数) int max_size()const; //返回string对象中可存放的最大字符串的长度 int size()const; //返回当前字符串的大小 int length()const; //返回当前字符串的长度 bool empty()const; //当前字符串是否为空 void resize(int len,char c);//把字符串当前大小置为len,并用字符c填充不足的部分 string类的输入输出操作: string类重载运算符operator>>用于输入,同样重载运算符operator<<用于输出操作。 函数getline(istream &in,string &s);用于从输入流in中读取字符串到s中,以换行符'\n'分开。 string的赋值: string &operator=(const string &s);//把字符串s赋给当前字符串 string &assign(const char *s);//用c类型字符串s赋值 string &assign(const char *s,int n);//用c字符串s开始的n个字符赋值 string &assign(const string &s);//把字符串s赋给当前字符串 string &assign(int n,char c);//用n个字符c赋值给当前字符串 string &assign(const string &s,int start,int n);//把字符串s中从start开始的n个字符赋给当前字符串 string &assign(const_iterator first,const_itertor last);//把first和last迭代器之间的部

C语言中常用的库函数

字符处理函数 本类别函数用于对单个字符进行处理,包括字符的类别测试和字符的大小写转换 头文件ctype.h 函数列表<> 函数类别函数用途详细说明 字符测试是否字母和数字isalnum 是否字母isalpha 是否控制字符iscntrl 是否数字isdigit 是否可显示字符(除空格外)isgraph 是否可显示字符(包括空格)isprint 是否既不是空格,又不是字母和数字的可显示字符ispunct 是否空格isspace 是否大写字母isupper 是否16进制数字(0-9,A-F)字符isxdigit 字符大小写转换函数转换为大写字母toupper 转换为小写字母tolower 地区化 本类别的函数用于处理不同国家的语言差异。 头文件local.h 函数列表 函数类别函数用途详细说明 地区控制地区设置setlocale 数字格式约定查询国家的货币、日期、时间等的格式转换localeconv 数学函数 本分类给出了各种数学计算函数,必须提醒的是ANSI C标准中的数据格式并不符合IEEE754标准,一些C语言编译器却遵循IEEE754(例如frinklin C51) 头文件math.h 函数列表 函数类别函数用途详细说明 错误条件处理定义域错误(函数的输入参数值不在规定的范围内) 值域错误(函数的返回值不在规定的范围内) 三角函数反余弦acos 反正弦asin

反正切atan 反正切2 atan2 余弦cos 正弦sin 正切tan 双曲函数双曲余弦cosh 双曲正弦sinh 双曲正切tanh 指数和对数指数函数exp 指数分解函数frexp 乘积指数函数fdexp 自然对数log 以10为底的对数log10 浮点数分解函数modf 幂函数幂函数pow 平方根函数sqrt 整数截断,绝对值和求余数函数求下限接近整数ceil 绝对值fabs 求上限接近整数floor 求余数fmod 本分类函数用于实现在不同底函数之间直接跳转代码。头文件setjmp.h io.h 函数列表 函数类别函数用途详细说明 保存调用环境setjmp 恢复调用环境longjmp 信号处理 该分类函数用于处理那些在程序执行过程中发生例外的情况。 头文件signal.h 函数列表 函数类别函数用途详细说明 指定信号处理函数signal 发送信号raise 可变参数处理 本类函数用于实现诸如printf,scanf等参数数量可变底函数。

c标准库函数大全

absread()读磁盘绝对扇区函数 原形:int absread(int drive,int num,int sectnum,void *buf) 功能:从drive指定的驱动器磁盘上,sectnum指定的逻辑扇区号开始读取(通过DOS中断0x25读取)num个(最多64K个)扇区的内容,储存于buf所指的缓冲区中。 参数:drive=0对应A盘,drive=1对应B盘。 返回值:0:成功;-1:失败。 头文件:dos.h abswrite()写磁盘绝对扇区函数 原形:int abswrite(int drive,int nsects,int lsect,void *buffer) drive=0(A驱动器)、1(B驱动器)、 nsects=要写的扇区数(最多64K个); lsect=起始逻辑扇区号; buffer=要写入数据的内存起始地址。 功能:将指定内容写入(调用DOS中断0x26)磁盘上的指定扇区,即使写入的地方是磁盘的逻辑结构、文件、FAT表和目录结构所在的扇区,也照常进行。 返回值:0:成功;-1:失败。 头文件:dos.h atof()将字符串转换成浮点数的函数 原形:double atof(const char *s) 功能:把s所指向的字符串转换成double类型。 s格式为:符号数字.数字E符号数字 返回值:字符串的转换值。 头文件:math.h、stdlib.h atoi()将字符串转换成整型数的函数 原形:int atoi(const char *s) 功能:把s所指向的字符串转换成int类型。 s格式为:符号数字 返回值:字符串的转换值。若出错则返回0。 头文件:stdlib.h atol()将字符串转换成长整型数的函数 原形:long atol(const char *s) 功能:把s所指向的字符串转换成long int类型。 s格式为:符号数字 返回值:字符串的转换值。若出错则返回0。 头文件:stdlib.h bcd()把一个数转换成对应的BCD码的函数 原形:bcd bcd(int x) bcd bcd(double x) bcd bcd(double x,int decimals)

string类中函数介绍

标准c++中string类函数介绍 注意不是CString 之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必担心内存是否足够、字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下(甚至是100%)的需要。我们可以用= 进行赋值操作,== 进行比较,+ 做串联(是不是很简单?)。我们尽可以把它看成是C++的基本数据类型。 好了,进入正题……… 首先,为了在我们的程序中使用string类型,我们必须包含头文件。 如下: #include //注意这里不是string.h string.h是C字符串头文件 #include using namespace std; 1.声明一个C++字符串 声明一个字符串变量很简单: string Str; 这样我们就声明了一个字符串变量,但既然是一个类,就有构造函数和析构函数。上面的声明没有传入参数,所以就直接使用了string的默认的构造函数,这个函数所作的就是把Str 初始化为一个空字符串。String类的构造函数和析构函数如下: a) string s; //生成一个空字符串s b) string s(str) //拷贝构造函数生成str的复制品 c) string s(str,stridx) //将字符串str内“始于位置stridx”的部分当作字符串的初值 d) string s(str,stridx,strlen) //将字符串str内“始于stridx且长度顶多strlen”的部分作为字符串的初值 e) string s(cstr) //将C字符串作为s的初值 f) string s(chars,chars_len) //将C字符串前chars_len个字符作为字符串s的初值。 g) string s(num,c) //生成一个字符串,包含num个c字符 h) string s(beg,end) //以区间beg;end(不包含end)内的字符作为字符串s的初值 i) s.~string() //销毁所有字符,释放内存 都很简单,我就不解释了。 2.字符串操作函数 这里是C++字符串的重点,我先把各种操作函数罗列出来,不喜欢把所有函数都看完的人可以在这里找自己喜欢的函数,再到后面看他的详细解释。 a) =,assign() //赋以新值 b) swap() //交换两个字符串的内容 c) +=,append(),push_back() //在尾部添加字符

数据库常用函数

数据库常用函数

一、基础 1、说明:创建数据库 CREATE DATABASE database-name 2、说明:删除数据库 drop database dbname 3、说明:备份和还原 备份:exp dsscount/sa@dsscount owner=dsscount file=C:\dsscount_data_backup\dsscount.dmp log=C:\dsscount_data_backup\outputa.log 还原:imp dsscount/sa@dsscount file=C:\dsscount_data_backup\dsscount.dmp full=y ignore=y log=C:\dsscount_data_backup\dsscount.log statistics=none 4、说明:创建新表 create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..) CREATE TABLE ceshi(id INT not null identity(1,1) PRIMARY KEY,NAME VARCHAR(50),age INT) id为主键,不为空,自增长 根据已有的表创建新表: A:create table tab_new like tab_old (使用旧表创建新表) B:create table tab_new as select col1,col2… from tab_old definition only 5、说明:删除新表 drop table tabname 6、说明:增加一个列 Alter table tabname add column col type 注:列增加后将不能删除。DB2中列加上后数据类型也不能改变,唯一能改变的是增加varchar类型的长度。 7、说明:添加主键: Alter table tabname add primary key(col) 说明:删除主键: Alter table tabname drop primary key(col) 8、说明:创建索引:create [unique] index idxname on tabname(col….) 删除索引:drop index idxname 注:索引是不可更改的,想更改必须删除重新建。 9、说明:创建视图:create view viewname as select statement 删除视图:drop view viewname 10、说明:几个简单的基本的sql语句 选择:select * from table1 where 范围 插入:insert into table1(field1,field2) values(value1,value2) 删除:delete from table1 where 范围 更新:update table1 set field1=value1 where 范围

string类的使用教程

这个是string类的使用教程,可以参考一下 之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必担心内存是否足够、字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下(甚至是100%)的需要。我们可以用= 进行赋值操作,== 进行比较,+ 做串联(是不是很简单?)。我们尽可以把它看成是C++的基本数据类型。 好了,进入正题……… 首先,为了在我们的程序中使用string类型,我们必须包含头文件。如下:#include //注意这里不是string.h string.h是C字符串头文件 1.声明一个C++字符串 声明一个字符串变量很简单: string Str; 这样我们就声明了一个字符串变量,但既然是一个类,就有构造函数和析构函数。上面的声明没有传入参数,所以就直接使用了string的默认的构造函数,这个函数所作的就是把Str初始化为一个空字符串。String类的构造函数和析构函数如下: a) string s; //生成一个空字符串s b) string s(str) //拷贝构造函数生成str的复制品 c) string s(str,stridx) //将字符串str内“始于位置stridx”的部分当作字符串的初值 d) string s(str,stridx,strlen) //将字符串str内“始于stridx且长度顶多strlen”的部分作为字符串的初值 e) string s(cstr) //将C字符串作为s的初值 f) string s(chars,chars_len) //将C字符串前chars_len个字符作为字符串s 的初值。 g) string s(num,c) //生成一个字符串,包含num个c字符 h) string s(beg,end) //以区间beg;end(不包含end)内的字符作为字符串s的初值 i) s.~string() //销毁所有字符,释放内存 都很简单,我就不解释了。 2.字符串操作函数 这里是C++字符串的重点,我先把各种操作函数罗列出来,不喜欢把所有函数都看完的人可以在这里找自己喜欢的函数,再到后面看他的详细解释。 a) =,assign() //赋以新值 b) swap() //交换两个字符串的内容 c) +=,append(),push_back() //在尾部添加字符 d) insert() //插入字符 e) erase() //删除字符 f) clear() //删除全部字符 g) replace() //替换字符 h) + //串联字符串 i) ==,!=,<,<=,>,>=,compare() //比较字符串 j) size(),length() //返回字符数量

c++常用函数大全

数学函数,所在函数库为math.h、stdlib.h、string.h、float.h int abs(int i) 返回整型参数i的绝对值 double cabs(struct complex znum) 返回复数znum的绝对值 double fabs(double x) 返回双精度参数x的绝对值 long labs(long n) 返回长整型参数n的绝对值 double exp(double x) 返回指数函数ex的值 double frexp(double value,int *eptr) 返回value=x*2n中x的值,n存贮在eptr中double ldexp(double value,int exp); 返回value*2exp的值 double log(double x) 返回logex的值 double log10(double x) 返回log10x的值 double pow(double x,double y) 返回xy的值 double pow10(int p) 返回10p的值 double sqrt(double x) 返回+√x的值 double acos(double x) 返回x的反余弦cos-1(x)值,x为弧度 double asin(double x) 返回x的反正弦sin-1(x)值,x为弧度 double atan(double x) 返回x的反正切tan-1(x)值,x为弧度 double atan2(double y,double x) 返回y/x的反正切tan-1(x)值,y的x为弧度double cos(double x) 返回x的余弦cos(x)值,x为弧度 double sin(double x) 返回x的正弦sin(x)值,x为弧度 double tan(double x) 返回x的正切tan(x)值,x为弧度 double cosh(double x) 返回x的双曲余弦cosh(x)值,x为弧度 double sinh(double x) 返回x的双曲正弦sinh(x)值,x为弧度 double tanh(double x) 返回x的双曲正切tanh(x)值,x为弧度 double hypot(double x,double y) 返回直角三角形斜边的长度(z), x和y为直角边的长度,z2=x2+y2 double ceil(double x) 返回不小于x的最小整数 double floor(double x) 返回不大于x的最大整数 void srand(unsigned seed) 初始化随机数发生器 int rand() 产生一个随机数并返回这个数 double poly(double x,int n,double c[])从参数产生一个多项式 double modf(double value,double *iptr)将双精度数value分解成尾数和阶 double fmod(double x,double y) 返回x/y的余数 double frexp(double value,int *eptr) 将双精度数value分成尾数和阶 double atof(char *nptr) 将字符串nptr转换成浮点数并返回这个浮点数 double atoi(char *nptr) 将字符串nptr转换成整数并返回这个整数 double atol(char *nptr) 将字符串nptr转换成长整数并返回这个整数 char *ecvt(double value,int ndigit,int *decpt,int *sign) 将浮点数value转换成字符串并返回该字符串

C语言常用的库函数

库函数并不是C语言的一部分,它是由编译系统根据一般用户的需要编制并 提供给用户使用的一组程序。每一种C编译系统都提供了一批库函数,不同的 编译系统所提供的库函数的数目和函数名以及函数功能是不完全相同的。ANSI C标准提出了一批建议提供的标准库函数。它包括了目前多数C编译系统所提供 的库函数,但也有一些是某些C编译系统未曾实现的。考虑到通用性,本附录 列出ANSI C建议的常用库函数。 由于C库函数的种类和数目很多,例如还有屏幕和图形函数、时间日期函数、 与系统有关的函数等,每一类函数又包括各种功能的函数,限于篇幅,本附录不 能全部介绍,只从教学需要的角度列出最基本的。读者在编写C程序时可根据 需要,查阅有关系统的函数使用手册。 1.数学函数 使用数学函数时,应该在源文件中使用预编译命令: #include或#include "math.h" 函数名函数原型功能返回值 acos double acos(double x);计算arccos x的值,其中-1<=x<=1计算结果 asin double asin(double x);计算arcsin x的值,其中-1<=x<=1计算结果 atan double atan(double x);计算arctan x的值计算结果 atan2double atan2(double x, double y);计算arctan x/y的值计算结果 cos double cos(double x);计算cos x的值,其中x的单位为弧度计算结果 cosh double cosh(double x);计算x的双曲余弦cosh x的值计算结果 exp double exp(double x);求e x的值计算结果

C 中的string常用函数用法总结.

C++中的string常用函数用法总结首先,为了在我们的程序中使用string类型,我们必须包含头文件。 如下: #include //注意这里不是string.h string.h是C字符串头文件 #include using namespace std; 1.声明一个C++字符串 声明一个字符串变量很简单: string Str; 这样我们就声明了一个字符串变量,但既然是一个类,就有构造函数和析构函数。上面的声明没有传入参数,所以就直接使用了string的默认的构造函数,这个函数所作的就是把Str 初始化为一个空字符串。String类的构造函数和析构函数如下: a) string s; //生成一个空字符串s b) string s(str) //拷贝构造函数生成str的复制品 c) string s(str,stridx) //将字符串str内“始于位置stridx”的部分当作字符串的初值 d) string s(str,stridx,strlen) //将字符串str内“始于stridx且长度顶多st rlen”的部分作为字符串的初值 e) string s(cstr) //将C字符串作为s的初值 f) string s(chars,chars_len) //将C字符串前chars_len个字符作为字符串s的初值。 g) string s(num,c) //生成一个字符串,包含num个c字符 h) string s(beg,end) //以区间beg;end(不包含end)内的字符作为字符串s的初值 i) s.~string() //销毁所有字符,释放内存 都很简单,我就不解释了。

String常见的操作和方法

String常见的操作和方法 String类适用于描述字符串事物 那么它就提供了多个方法对字符串进行操作。 常见的操作有哪些? “afbs” 1、获取 1.1 字符串中包含的字符数,也就是字符串的长度。 int length(): 获取长度。 1.2 根据位置获取位置上某个字符。 char charAt(int index): 1.3 根据字符获取字符在字符串中位置。 int indexOf(int ch): 返回的是ch在字符串中第一次出现的位置。 int indexOf(int ch, int fromIndex): 从fromIndex指定位置开始,获取ch在字符串中出现的位置。 int indexOf(int str): 返回的是str在字符串中第一次出现的位置。 int indexOf(int str, int fromIndex): 从fromIndex指定位置开始,获取str在字符串中出现的位置。 int lastIndexOf(int ch); 2、判断。 2.1 字符串中是否包含某一个子串。 boolean contains(str): 特殊之处:indexOf(str):可以索引str第一次出现的位置,如果返回-1.表示该str不存在字符串中。 所以,也可以用于对指定判断是否包含。 if(str.indexOf("aa")!=-1) 而且该方法既可以判断,又可以获取出现的位置。 2.2 字符串中是否有内容。

boolean ifEmpty(): 原理就是判断长度是否为0. 2.3 字符串是否是以指定内容开头。 boolean startsWith(str); 2.4 字符串是否是以指定内容结尾。 boolean endsWith(str); 2.5判断字符串内容是否相同。复写了Object类中的equals方法。boolean equals(str); 2.6判断内容是否相同,并忽略大小写。 boolean equalsIgnoreCase(); 3、转换 3.1 将字符数组转成字符串。 构造函数:String(char[]) String(char[],offset,count):将字符数组中的一部分转成字符串。 静态方法: static String copyValueOf(char[]); static String copyValueOf(char[] data,int offset,int count) static String valueOf(char[]): 3.2 将字符串转成字符数组。 char[] toCharArray(): 3.3 将字节数组转成字符串。 String(byte[]) String(byte[],offset,count):将字节数组中的一部分转成字符串。 3.4 将字符串转成字节数组。** byte[] getBytes(): 3.5 将基本数据类型转成字符串。 static String valueOf(int) static String valueOf(double) 3+"";//String.valueOf(3); 特殊:字符串和字节数组在转换过程中,是可以指定编码表的。

C语言中最常用标准库函数 - candyliuxj - CSDN博客

C语言中最常用标准库函数- candyliuxj - CSDN博客 C语言中最常用标准库函数收藏 标准头文件包括: <asset.h> <ctype.h> <errno.h> <float.h> <limits.h> <locale.h> <math.h> <setjmp.h> <signal.h> <stdarg.h> <stddef.h> <stdlib.h> <stdio.h> <string.h> <time.h> 一、标准定义(<stddef.h>) 文件<stddef.h>里包含了标准库的一些常用定义,无论我们包含哪个标准头文件,<stddef.h>都会被自动包含进来。 这个文件里定义: l 类型size_t (sizeof运算符的结果类型,是某个无符号整型); l 类型ptrdiff_t(两个指针相减运算的结果类型,是某个有符号整型);

l 类型wchar_t (宽字符类型,是一个整型,其中足以存放本系统所支持的所有本地环境中的 字符集的所有编码值。这里还保证空字符的编码值为0); l 符号常量NULL (空指针值); l 宏offsetor (这是一个带参数的宏,第一个参数应是一个结构类型,第二个参数应是结构 成员名。offsetor(s,m)求出成员m在结构类型t的变量里的偏移量)。 注:其中有些定义也出现在其他头文件里(如NULL)。 二、错误信息(<errno.h>) <errno.h>定义了一个int类型的表达式errno,可以看作一个变量,其初始值为0,一些标准库函数执行中出错时将它设为非0值,但任何标准库函数都设置它为0。 <errno.h>里还定义了两个宏EDOM和ERANGE,都是非0的整数值。数学函数执行中遇到参数错误,就会将errno 置为EDOM,如出现值域错误就会将errno置为ERANGE。 三、输入输出函数(<stdio.h>) 文件打开和关闭: FILE *fopen(const char *filename, const char *mode); int fclose(FILE * stream);

C++string类常用函数

string类的构造函数: string(const char *s); //用c字符串s初始化 string(int n,char c); //用n个字符c初始化 此外,string类还支持默认构造函数和复制构造函数,如string s1;string s2="hello";都是正确的写法。当构造的string太长而无法表达时会抛出length_error异常 string类的字符操作: const char &operator[](int n)const; const char &at(int n)const; char &operator[](int n); char &at(int n); operator[]和at()均返回当前字符串中第n个字符的位置,但at函数提供范围检查,当越界时会抛出out_of_range异常,下标运算符[]不提供检查访问。 const char *data()const;//返回一个非null终止的c字符数组 const char *c_str()const;//返回一个以null终止的c字符串 int copy(char *s, int n, int pos = 0) const;//把当前串中以pos开始的n个字符拷贝到以s为起始位置的字符数组中,返回实际拷贝的数目 string的特性描述: int capacity()const; //返回当前容量(即string中不必增加内存即可存放的元素个数) int max_size()const; //返回string对象中可存放的最大字符串的长度 int size()const; //返回当前字符串的大小 int length()const; //返回当前字符串的长度 bool empty()const; //当前字符串是否为空 void resize(int len,char c);//把字符串当前大小置为len,并用字符

C++ 中的STRING类 的各种操作说明

之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必 担心内存是否足够、字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下(甚至是100%)的需要。我们可以用 = 进行赋值操作,== 进行比较,+ 做串联(是不是很简单?)。我们尽可以把它看成是C++的基本数据类型。 首先,为了在我们的程序中使用string类型,我们必须包含头文件 。如下: #include //注意这里不是string.h string.h是C字符串头文件 1.声明一个C++字符串 声明一个字符串变量很简单: string Str; 这样我们就声明了一个字符串变量,但既然是一个类,就有构造函数和析构函数。上面的声明没有传入参数,所以就直接使用了string的默认的构造函数,这个函数所作的就是把Str初始化为一个空字符串。String 类的构造函数和析构函数如下: a) string s; //生成一个空字符串s b) string s(str) //拷贝构造函数生成str的复制品 c) string s(str,stridx) //将字符串str内"始于位置stridx"的部分当作字符串的初值 d) string s(str,stridx,strlen) //将字符串str内"始于stridx且长度顶多strlen"的部分作为字符串的初值 e) string s(cstr) //将C字符串作为s的初值 f) string s(chars,chars_len) //将C字符串前chars_len个字符作为字符串s的初值。 g) string s(num,c) //生成一个字符串,包含num个c字符 h) string s(beg,end) //以区间beg;end(不包含end)内的字符作为字符串s的初值 i) s.~string() //销毁所有字符,释放内存 都很简单,我就不解释了。 2.字符串操作函数 这里是C++字符串的重点,我先把各种操作函数罗列出来,不喜欢把所有函数都看完的人可以在这里找自己喜欢的函数,再到后面看他的详细解释。 a) =,assign() //赋以新值 b) swap() //交换两个字符串的内容 c) +=,append(),push_back() //在尾部添加字符 d) insert() //插入字符 e) erase() //删除字符 f) clear() //删除全部字符 g) replace() //替换字符 h) + //串联字符串 i) ==,!=,<,<=,>,>=,compare() //比较字符串 j) size(),length() //返回字符数量 k) max_size() //返回字符的可能最大个数 l) empty() //判断字符串是否为空 m) capacity() //返回重新分配之前的字符容量 n) reserve() //保留一定量内存以容纳一定数量的字符 o) [ ], at() //存取单一字符

相关主题
文本预览
相关文档 最新文档