C++中LIST和String用法

C++中LIST和String用法
C++中LIST和String用法

1.c++中的list用法

#include

#include

#include

#include

using namespace std;

//创建一个list容器的实例LISTINT

typedef list LISTINT;

//创建一个list容器的实例LISTCHAR

typedef list LISTCHAR;

void main(void)

{

//--------------------------

//用list容器处理整型数据

//--------------------------

//用LISTINT创建一个名为listOne的list对象

LISTINT listOne;

//声明i为迭代器

LISTINT::iterator i;

//从前面向listOne容器中添加数据

listOne.push_front (2);

listOne.push_front (1);

//从后面向listOne容器中添加数据

listOne.push_back (3);

listOne.push_back (4);

//从前向后显示listOne中的数据

cout<<"listOne.begin()--- listOne.end():"<

for (i = listOne.begin(); i != listOne.end(); ++i)

cout<< *i << " ";

cout<

//从后向后显示listOne中的数据

LISTINT::reverse_iteratorir;

cout<<"listOne.rbegin()---listOne.rend():"<

for (ir =listOne.rbegin(); ir!=listOne.rend();ir++) {

cout<< *ir<< " ";

}

cout<

//使用STL的accumulate(累加)算法

int result = accumulate(listOne.begin(), listOne.end(),0);

cout<<"Sum="<

cout<<"------------------"<

//--------------------------

//用list容器处理字符型数据

//--------------------------

//用LISTCHAR创建一个名为listOne的list对象

LISTCHAR listTwo;

//声明i为迭代器

LISTCHAR::iterator j;

//从前面向listTwo容器中添加数据

listTwo.push_front ('A');

listTwo.push_front ('B');

//从后面向listTwo容器中添加数据

listTwo.push_back ('x');

listTwo.push_back ('y');

//从前向后显示listTwo中的数据

cout<<"listTwo.begin()---listTwo.end():"<

for (j = listTwo.begin(); j != listTwo.end(); ++j)

cout<< char(*j) << " ";

cout<

//使用STL的max_element算法求listTwo中的最大元素并显示j=max_element(listTwo.begin(),listTwo.end());

cout<< "The maximum element in listTwo is: "<

}

#include

#include

using namespace std;

typedef list INTLIST;

//从前向后显示list队列的全部元素

voidput_list(INTLIST list, char *name)

{

INTLIST::iterator plist;

cout<< "The contents of " << name << " : ";

for(plist = list.begin(); plist != list.end(); plist++)

cout<< *plist<< " ";

cout<

}

//测试list容器的功能

void main(void)

{

//list1对象初始为空

INTLIST list1;

//list2对象最初有10个值为6的元素

INTLIST list2(10,6);

//list3对象最初有3个值为6的元素

INTLIST list3(list2.begin(),--list2.end());

//声明一个名为i的双向迭代器

INTLIST::iterator i;

//从前向后显示各list对象的元素

put_list(list1,"list1");

put_list(list2,"list2");

put_list(list3,"list3");

//从list1序列后面添加两个元素

list1.push_back(2);

list1.push_back(4);

cout<<"list1.push_back(2) and list1.push_back(4):"<

//从list1序列前面添加两个元素

list1.push_front(5);

list1.push_front(7);

cout<<"list1.push_front(5) and list1.push_front(7):"<

//在list1序列中间插入数据

list1.insert(++list1.begin(),3,9);

cout<<"list1.insert(list1.begin()+1,3,9):"<

put_list(list1,"list1");

//测试引用类函数

cout<<"list1.front()="<

cout<<"list1.back()="<

//从list1序列的前后各移去一个元素

list1.pop_front();

list1.pop_back();

cout<<"list1.pop_front() and list1.pop_back():"<

put_list(list1,"list1");

//清除list1中的第2个元素

list1.erase(++list1.begin());

cout<<"list1.erase(++list1.begin()):"<

put_list(list1,"list1");

//对list2赋值并显示

list2.assign(8,1);

cout<<"list2.assign(8,1):"<

put_list(list2,"list2");

//显示序列的状态信息

cout<<"list1.max_size(): "<

cout<<"list1.size(): "<

cout<<"list1.empty(): "<

//list序列容器的运算

put_list(list1,"list1");

put_list(list3,"list3");

cout<<"list1>list3: "<<(list1>list3)<

cout<<"list1

//对list1容器排序

list1.sort();

put_list(list1,"list1");

//结合处理

list1.splice(++list1.begin(), list3);

put_list(list1,"list1");

put_list(list3,"list3");

}

2.标准C++中的string类的用法总结

相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用。但是如果离开了MFC框架,还有没有这样使用起来非常方便的类呢?答案是肯定的。也许有人会说,即使不用MFC框架,也可以想办法使用MFC中的API,具体的操作方法在本文最后给出操作方法。其实,可能很多人很可能会忽略掉标准C++中string类的使用。标准C++中提供的string类得功能也是非常强大的,一般都能满足我们开发项目时使用。现将具体用法的一部分罗列如下,只起一个抛砖引玉的作用吧,好了,废话少说,直接进入正题吧!

要想使用标准C++中string类,必须要包含

#include // 注意是,不是,带.h的是C语言中的头文件using std::string;

using std::wstring;

或using namespace std;

下面你就可以使用string/wstring了,它们两分别对应着char和wchar_t。

string和wstring的用法是一样的,以下只用string作介绍:

string类的构造函数:

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

string(intn,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, intpos = 0) const;//把当前串中以pos开始的n个字符拷贝到以s为起始位置的字符数组中,返回实际拷贝的数目

string的特性描述:

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

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

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

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

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

void resize(intlen,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(intn,char c);//用n个字符c赋值给当前字符串

string &assign(const string &s,intstart,int n);//把字符串s中从start开始的n个字符赋给当前字符串

string &assign(const_iteratorfirst,const_itertor 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,intpos,int n);//把字符串s中从pos开始的n个字符连接到当前字符串的结尾

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

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

string的比较:

bool operator==(const string &s1,const string &s2)const;//比较两个字符串是否相等运算符">","<",">=","<=","!="均被重载用于字符串的比较;

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

int compare(intpos, intn,const string &s)const;//比较当前字符串从pos开始的n个字

符组成的字符串与s的大小

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

//pos2开始的n2个字符组成的字符串的大小

int compare(const char *s) const;

int compare(intpos, intn,const char *s) const;

int compare(intpos, intn,const char *s, int pos2) const;

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

string的子串:

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

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

string类的查找函数:

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

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

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

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

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

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

intrfind(const char *s, intpos = npos) const;

intrfind(const char *s, intpos, int n = npos) const;

intrfind(const string &s,intpos = npos) const;

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

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

intfind_first_of(const char *s, intpos, int n) const;

intfind_first_of(const string &s,intpos = 0) const;

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

intfind_first_not_of(char c, intpos = 0) const;

intfind_first_not_of(const char *s, intpos = 0) const;

intfind_first_not_of(const char *s, intpos,int n) const;

intfind_first_not_of(const string &s,intpos = 0) const;

//从当前串中查找第一个不在串s中的字符出现的位置,失败返回string::npos intfind_last_of(char c, intpos = npos) const;

intfind_last_of(const char *s, intpos = npos) const;

intfind_last_of(const char *s, intpos, int n = npos) const;

intfind_last_of(const string &s,intpos = npos) const;

intfind_last_not_of(char c, intpos = npos) const;

intfind_last_not_of(const char *s, intpos = npos) const;

intfind_last_not_of(const char *s, intpos, int n) const;

intfind_last_not_of(const string &s,intpos = npos) const;

//find_last_of和find_last_not_of与find_first_of和find_first_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, intpos, 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, intpos, 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(intpos = 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_iteratorrbegin()const;

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

const_iterator rend()const;

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

rbegin和rend用于从后向前的迭代访问,通过设置迭代器

string::reverse_iterator,string::const_reverse_iterator实现

字符串流处理:

通过定义ostringstream和istringstream变量实现,#include 头文件中例如:

string input("hello,this is a test");

istringstream is(input);

string s1,s2,s3,s4;

is>>s1>>s2>>s3>>s4;//s1="hello,this",s2="is",s3="a",s4="test"

ostringstreamos;

os<

cout<

中考英语口语辅导:consider的用法

中考英语口语辅导:consider的用法 表示“考虑”,其后可接动名词,但不能接不定式。如He is considering changing his job. 他在考虑调换工作。I’ve never really considered getting married. 我从未考虑过结婚的事。注:consider 之后虽然不能直接跟不定式,但可跟“疑问词+不定式”结构。如Have you considered how to get there / how you could get there. 你是否考虑过何到那儿去?2. 表示“认为”、“把……看作”,下面三个句型值得注意(有时三者可互换) (1) consider +that从句(2) consider+宾语+(as +)名词或形容词(3) consider+宾语+(to be +)名词或形容词I consider him (as) honest (或an honest man). I consider him (to be) honest (或an honest man). I consider that he is honest (或an honest man). 注:(1) 以上备句意思大致相同,对于consider 之后能否接as 的问题,尚有不同看法(即有人认为不能接as ,有人认为可以拉as,但实际上接as 的用法已很普遍)。(2) 在“consider+宾语”之后除可接to be 外,有时也可to do 型动词(但多为完成形式)。如We all considered him to have acted disgracefully. 我们都认为他的行为很不光彩。

疑问代词用法总结及练习

疑问代词用法总结及练习 句子是英语学习的核心。从句子使用的目的来分,它可分为四类 1、陈述句(肯定句和否定句) 2、疑问句(一般疑问句、特殊疑问句和选择疑问句) 3、祈使句(肯定句和否定句) 4、感叹句。 四大句子类型的相互转换,对于学生来讲是个难点,为此,可通过说顺口溜的形式来帮助学生解决这一难题。 如:将陈述句变成一般疑问句,可以变成这样的顺口留:疑问疑问调个头,把be(系动词“is are am”)放在最前头。 如:将陈述句的肯定句变成否定句,我们就可以这样说:否定,否定加“not”,加在何处,加在系动词的后面。 在句子相互转换的题型中,最难的要算“就下列划线部分提问”或是“看答句,写问句”这种题型了,其实,我们只要熟练掌握疑问词(what,what time, what colour, where, when, who, whose, which, how, how old ,how tall, how long, how big, how heavy , how much, how many等等)具体用法。

习题 一、选择正确的单词填空 (who, where, when) is that pretty girl She is my sister. are Jack and Tom They are behind you. do you go to school I go to school from Monday to Friday. has a beautiful flower John has a beautiful flower.

are they They are my parents. is my mother She is in the living room. are you going We are going to the bakery(面包坊). Jim and Wendy play ball They play ball in the afternoon. does he jog He jogs in the park. are you from I'm from Changchun city. 11. _______ is your birthday –On May 2nd. 12、_______ are you --- I`m in the office. 13. are you ---- I`m Alice. 二.用(what time, what color, what day, what)填空。 1. A: ______ _______ is it B: It is nine o’clock. 2. A: ______ _______ does your mother get up B: My mother gets up at 6:30. 3. A: ______ _______ do you go to bed B: I go to bed at 10:00. 4. A: ______ _______ do Diana and Fiona have supper B: Diana and Fiona have supper at 18:00. 5. A: ______ _______is it B: It is purple. 6. A: ______ _______ is the sky B: The sky is blue. 7. A: ______ _______ is your coat B: My coat is black. 8. A: ______ _______ is the dog B: The dog is white. 9. A: ______ _______ is today B: Today is Monday. 10. A: ______ _______ is tomorrow B: Tomorrow is Tuesday. 11. A: ______ _______ was yesterday B: Yesterday was Sunday. 12. A: ______ _______ do you like B: I like red. 13. A: ______ is this This is a computer. 14. A: ______ are you doing B: We are playing basketball.

java String类的用法

1 String 类的用法 public class SetStringValue { /** * @param args */ public static void main(String[] args) { String str1=new String("Java是当今最流行的编程语言之一");//截取数组 String str2="java是优秀的技术"; char[] szStr={'H','e','l','l','o',',','j','a','v','a'}; String str3=String.copyValueOf(szStr);//复制数组,所有数组。 String str4=String.copyValueOf(szStr,6,4);//所取数组,开始位置,所取个数 System.out.println(str1); System.out.println(str2); System.out.println(str3); System.out.println(str4); // TODO Auto-generated method stub } } 2 public class StringPool { /** * @param args */ public static void main(String[] args) { String str1="Good!"; String str2="Good!"; String str3=new String("Good!"); if(str1==str2)//判断地址是否相同 { System.out.println("str1=str2");//地址相同则输出相等

consider的基本用法及与regardthinkofabout

consider的基本用法及与regard,think ofabout和look(up)on as的区别 consider的基本用法及与regard,think of/about和look(up)on as的区别 consider一词在历年高考中是一个常考的要点,其用法应分为两部分来讲。第一、作“考虑、思考”时的搭配如下: 1.consider+n./pron.,例如: Have you considered the suggestion? That’s what we have to consider now. 2.consider+v-ing,但不能接不定式的一般式,例如: We considered going to see the doctor the next day. Have you considered moving to shanghai recently? You must consider to tell him something about it.(错误) 3.consider+疑问词+不定式,例如: He is considering how to improve his English. We must consider what to do next.

4.consider+从句,例如: We didn’t consider whether he should go or not. Have you considered when we should go there? 第二、作“认为、把……当作/看作”等意思时的搭配如下:1.consider+sb/sth+(to be/as)+n./adj.,例如: I consider him to(be/as)my best friend. Everyone considers him(to be)clever. He considered it much improved. 2.consider+sb./sth.+不定式短语(作宾语补足语),不能接不定式的一般式,例如: We consider them to be working very hard. We consider them to have finished the work. We consider him to be the clever in our class. We must consider him to go there at once.(错误) 3.consider+it+adj./n.+不定式短语,其中it为形式宾语,不定式短语为真正的宾语,例如: Jiao Yulu considered it his duty to serve the people heart and soul. They consider it necessary to set the slaves free.

英语一般疑问句用法总结

英语一般疑问句用法总结 1. 基本用法及结构 一般疑问句用于对某一情况提出疑问,通常可用yes和no来回答,读时用升调。其基本结构是“be / have / 助动词+主语+谓语(表语)”: Is he interested in going? 他有兴趣去吗? Have you ever been to Japan? 你到过日本吗? Does she often have colds? 她常常感冒吗? Did you ask her which to buy? 你问没问她该买哪一个? 2. 陈述句变一般疑问句的方法 (1) 动词be的否定式。动词be根据不同的时态和人称可以有am, is, are, was, were等不同形式,可用作连系动词(表示“是”、“在”等)和助动词(用于构成进行时态和被动语态等),但不管何种情况,构成疑问式时,一律将动词be的适当形式置于句首: Am I right? 我是对的吗? Are you feeling better today? 你今天感到好些了吗? Was he late for school? 他上学迟到了吗? (2) 动词have的疑问式。动词have根据不同的时态和人称可以有have, has, had等形式,可以用作实意动词和助动词,分以下情况讨论:

①用作实意动词表示状态,如表示拥有、患病或用于have to 表示“必须”等,在构成构成式时可以直接将have, has, had置于句首,也可根据情况在句首使用do, does, did: Does he have [Has he] anything to say? 他有什么话要说吗? Do you have [Have you] to leave so soon? 你必须这么早走吗? Did you have [Had you] any friends then? 他当时有朋友吗? ②用作实意动词表示动作,如表示“吃(=eat)”、“喝(=drin k)”、“拿(=take)”、“收到(=receive)”、“度过(=spend)”等,构成疑问式时不能将have提前至句首,而应在句首使用do, does, did: Does he have breakfast at home? 他在家吃早餐吗? Did you have a good time at the party? 你在晚会上玩得高兴吗? ③用作助动词构成完成时态,其疑问式总是将have等置于句首: Have you finished your work? 你的工作做完了吗? Has he left when you arrived? 你到达时他已离开了吗? (3) 情态动词的疑问式。情态动词的疑问式通常是将情态动词置于句首: Can you speak English? 你会说英语吗?

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语言去实现这个流程。如果一个人的主要工作就是处理这种

Consider的用法

Consider的用法: -Have you considered_____ the job ss a teacher? -Yes.I like it because a teacher is often considered _______ a gardener. A.to take,to be B.to take,being C.taking,being D.taking,to be 答案:d译文:你考虑过做老师的工作吗? 是的,我非常喜欢,因为老师通常被认为是园丁 一、consider作“考虑”解,常用于以下句型: 1.consider+名词/代词/动名词。 You'd better consider my suggestion. 你最好考虑我的建议。 I’m considering going abroad some day.我一直考虑有一天出国。 2.consider+从句或“疑问词+不定式”。 Have you considered what he suggested? 你们考虑他的建议了吗? We must consider what to do next. 我们必须考虑下一步要做什么。 二.consider作“认为”解时,常用于以下句型: 1.consider sb./sth+.(as)+形容词/名词。其中,as可以省略。 We consider him honest. 我们认为他很诚实。 At first they considered me as a doctor.起初他们认为我是医生。 2.consider+sb./sth.+不定式。其中,不定式通常是to be(可以省略)或其他动词的完成式。We consider this matter to be very important. 我们认为这件事很重要。 We all consider him to have stolen the bike.我们都认为他偷了自行车。 3.consider+it+形容词/名词+不定式短语。 We consider it hard to study English well.我们认为学好英语很难。 I consider it my duty to help you with your studies.我认为帮助你学习英语是我的职责。 4.consider+宾语从句。 We consider that the music is well worth listening to.我们这首音乐很值得一听。 在该题中,前一个句子中的consider作“考虑”解,后接动名词作宾语,但不可接不定式,由此可以排除A, B; 后一个句子中的consider作“认为”解,用到句型consider+sb./sth.+不定式,此处使用的是被动语态结构。故答案为D项。 请看下面两道考题,均考查“with+宾语+非谓语动词”结构: 1.—Come on, please give me some ideas about the project. —Sorry. With so much work _________my mind, I almost break down. A.filled B.filling C.to fill D.being filled 2.John received an invitation to dinner, and with his work _________, he gladly acc epted it. A.finished B.finishing C.having finished D.was finished 以上两题答案分别为B和A,均考查“with+宾语+非谓语动词”结构。该结果中的“非谓语动词”可以是不定式、现在分词、过去分词,它们在用法上的区别如下:

一般疑问句、选择疑问句的详细用法备课讲稿

一般疑问句、选择疑问句的详细用法

一般疑问句、 (一)一般疑问句 1、一般疑问句概述 一般疑问句(general questions),也可称为“yes/no” questions(是否型问句),因为它一般是由yes或no回答的,如: —Can you swim to the other side?你能游到对岸吗? —Yes, I can.是的,我能。 —No,I can’t.不,我不能。 —Have you locked the door?你锁门了吗? —Yes,I have.是的,锁了。 —No,I haven’t. 不,没有锁。 2一般疑问句的结构 (1)基本的结构为:be/助动词/情态动词+主语+谓语/表语+(其他),句子要读升调,如: Are they your friends?他们是你的朋友吗? Does he go to school on foot?他是步行去上学吗? Will you be free tonight?你今晚有空吗? Can you play basketball?你会打篮球吗? (2)陈述句亦可用作一般疑问句,多用在非正式文体中,句末有问号,用升调,如: Somebody is with you?有人和你一起吗? He didn’t finish the work?他没有做完活吗? You are fresh from America,I suppose?我猜,你刚从美国回来吧? 3、一般疑问句的答语 (1)一般疑问句一般由yes或no来回答,如: —Are you tired?你累了吗? —Yes,I am.是的,累了。 —No, I’m not.不,不累。 —Does she do the cleaning?她扫除了吗?

consider的用法归纳有哪些

consider的用法归纳有哪些 consider的用法:作名词 consideration作名词,意为careful thought and attention斟酌,考虑 Several considerations have influenced my decision.好几个因素影响了我的决定。 1.Consideration for顾及,体贴 He has never shown much consideration for his wife’s needs.他从来不顾及他妻 子的需要。 2.Under consideration在讨论/考虑中 Several projects are under consideration.好几个项目在讨论中。 There are some proposals under consideration. 有几个建议在审议中。 3.Take sth. into consideration考虑到某事,体谅 Your teachers will take your recent illness into consideration when marking your exams. 你的几位老师在给你的考试评分时,会考虑你最近生病这一情况的。 4.Leave sth. out of consideration 忽略/不重视某事 It was wrong to leave my feelings out of consideration.不顾及我的情感是不对的。 5.Show consideration for体谅,顾及 Jeff never shows any consideration for his mother’s feelings.杰夫从来不体谅他 母亲的感受。 6.of. No / little consideration无关紧要的,不重要的 Whether he would go with us or not was of no consideration. 他是否跟我们一起 去是无关紧要的。 7.In consideration of sth.作为对……的汇报,考虑到 It’s a small payment in consideration of your services.这是答谢您服务的微薄酬金。 consider的用法:作动词 1.Consider作动词,意为think about sth.考虑,斟酌 常用搭配:consider sth. / doing sth. / where(how, why)+to do /that clause; all things considered通盘考虑,考虑到问题的各个方面。如:

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() //返回字符数量

特殊疑问句和一般疑问句的用法

(一)由be(am,is,are)引导的一般疑问句 1、Am I a student? 我是学生吗? Yes,you are./ No,you aren’t. 2、Is this /that/it a chair?这/那/它/是一把椅子吗? Yes,it is. /No,it isn’t. 3、Is she/Amy your sister?她/艾米是你的妹妹吗?Yes,she is ./ No,she isn’t. 4、Is he/Mike your brother?他/迈克是你的哥哥吗?Yes,he is./No,he isn’t. 5、Is your brother helpful at home? 你哥哥在家有用吗?Yes, he is./ No, he isn’t. 6、Is there a forest in the park? 在公园有一个森林吗? Yes,there is./No,there isn’t. 是的,有。/不,没有。 7、Are there any panda s in the mountains?在山上有熊猫吗? Yes,there are./No,there aren’t.是的,有。/不,没有。 8、Are they dusk s? 它们是鸭子吗?(问物) Yes, they are. /No,they aren’t.是的,它们是。/不,它们不是。 9、Are they famers? 他们是农民吗?(问人) Yes, they are. /No,they aren’t. 是的,他们是。/不,他们不是。 10、Are you a teacher?你是一个老师吗?(问you 用I回答) Yes, I am./No,I’m not.是的,我是。/不,我不是。 11、Are you teacher s?你们是老师吗? Yes,we are./No,we aren’t.是的,我们是。/不,我们不是。 (二)、由do引导的一般疑问句

C++ string类专题(修订版)

本文作者:黄邦勇帅(编著)(原名:黄勇) 本文是学习C++的附加内容,主要介绍了C++中的string类的各种成员函数,及成员函数的功能与作用,是作为学习C++的参考使用的。 本文内容完全属于个人见解与参考文现的作者无关,其中难免有误解之处,望指出更正 本文使用的是x86机器(主流计算机都是x86机器),windows xp操作系统,VC++2010编译器进行讲解的。 本文内容完全属于个人见解与参考文现的作者无关,限于水平有限,其中难免有误解之处,望指出更正。 声明:禁止抄袭,复印,转载本文,本文作者拥有完全版权。 主要参考文献: 1、C++.Primer.Plus.第五版.中文版[美]Stephen Prata著孙建春韦强译人民邮电出版社 2005年5月 2、C++.Primer第四版.中文版 Stanley B.Lippman、Barbara E.Moo、Josee Lajoie著李师贤、蒋爱军等译人民邮电出版社 2006年3月 3、C++.Primer第三版.中文版 Stanley B.Lippman、Josee Lajoie著潘爱民、张丽等译中国电力版社 2002年5月 第19部分 string类专题(共9页) (2016-7-15 修订版) 1、string类用于处理字符串,用于代替使用不方便的C风格字符串,使用string类表示的字符串我们可以像处理普通 变量那样处理字符串,因此可以对string类表示的字符串进行直接的相加,比较,赋值等操作,比如string s1=”abc”,s2=”def”;则s1=s1+s2;结果s1=”abcdef”;s1=s2;则结果s1=”def” 等,C风格字符串只能使用内置的库函数进行这些操作,使用很不方便,比如char c1[]=”abc”; char c2[]=”def”;则c1=c2;错误,不能改变数组的地址,c1>c2比较的是两个指针的地址而不是字符的大小;c1+c2;错误,这是把两个指针的地址相加而不是把两个字符数组相加。 2、string对象创建的字符串的最大特点是:可以自动调整对象大小以适应所需的字符串,string对象能存储的最大字符 数由string类的静态常量string::npos设定,通常是最大的unsigned int值。 一、string类的原型 1、要使用string类需要包含string头文件。 2、string是一个模板类,因此它具有类和模板的特性,也就是说string类有构造函数、重载的操作符、成员函数等, 因为string是模板类,因此应建一个模板类具体实例化版本的对象才能使用,然后通过对象调用成员函数使用类。 3、记住string s;创建的s是一个类的对象,而不是字符串字面值,他们是两种不同的类型。 4、string类是模板类basic_string类的char特化体版本使用typedef命名后的别名,wstring类是模板类basic_string的 wchar特体化版本使用typedef命名后的别名。 5、basic_string类的原型为(重点): template, class Allocator=allocator > class basic_string; 1)、charT是个类型模板形参,若实例化时传递char类型,则charT=char,传递wchar则charT=wchar 2)、traits是类型模板形参,描述了字符串的特征,比如字符串是否以’\0’作为结束尾等。traits要求传递一个 char_traits的模板类型作为实参。 3)、Allocator也是个类模板形参,他的主要作用是用于处理字符串的内存分配问题,默认使用new和delete分配内 存。Allocator要求传递一个allocator类型的模板类型作为实参。 4)、basic_string有两个特化体版本(重点),如下所示,当然我们也可以实例化其他类型版本的base_string类模板, ①、typedef base_string string; //即string类是使用typedef重命名后的basic_string类模板的char特化体版本。 ②、typedef base_string wstring; //主要用于处理宽字符串。 6、size_type类型(重要):size_type是basic_string类中定义的类型,一般被定义为unsigned类型。需要使用限定名的 方法来使用size_type类型,比如string::size_type a;或basic_string::size_type a; 7、npos静态常量(重要):表示string对象能够存储的最大字符数,其形式为:static const size_type npos=-1; 可见npos 是basic_string类中定义的静态常量,其类型为size_type其值为-1,对于无符号的size_type变量,赋值为-1,相当于是把最大的无符号数赋值给了他。 二、string类的构造函数 1、basic_string的构造函数与char特化版本的string构造函数的差别,只在于basic_string构造函数多了一个用于分配

否定疑问句的构成和用法

否定疑问句的构成和用法 反意疑问句是在陈述句后边加上一个简短问句,对陈述句所叙述的内容提出相反的疑问,这种句子就叫作反意疑问句。反意疑问句可以表示真实的疑问,也可以表示提问人的倾向、强调或反问。如果陈述句是肯定句时,后边的反意疑问句通常要用否定式;反之,如果陈述句是否定句时,后边的反意疑问句通常要用肯定式。陈述句和后边的反意疑问句的主语以及谓语动词的人称、数、时态通常要保持一致。例如: He speaks English, doesn't he? Mary won't do it, will she? Lies cannot cover up the facts, can they? 回答反意疑问句和回答一般疑问句一样,肯定回答用"Yes, +肯定结构";否定回答用"No, +否定结构"。这与汉语习惯有所不同。例如: -He's a doctor, isn't he?他是医生,对吧? -Yes, he is.对,他是医生。(No, he isn't.不,他不是医生。) -He isn't a doctor, is he?他不是医生,对吧? -Yes, he is.不,他是医生。(No, he isn't.对,他不是医生。) 在使用反意疑问句时,特别要注意以下几点: 1.当动词have作"有"讲时,可以有两种反意疑问句形式。例如: He hasn't any sisters, has he? He doesn't have any sisters, does he? 当have表示其它含义(如:经历、遭受、得到、吃……)讲时,只有一种反意疑问句形式: You all had a good time, didn't you? He often has colds, doesn't he? They had milk and bread for breakfast, didn't they? 2.如果陈述句的谓语动词含有have to, had to时,反意疑问句通常用其适当形式。例如: We have to get there at 8 a.m. tomorrow, don't we? They had to take the early train, didn't they? 3. need和dare既可以作情态动词,又可以作实义动词,注意有两种反意疑问句形式。例如: You needn't hand in your paper today, need you? You don't need to hand in your paper today, do you? He dare ask the teacher, dare not he? He doesn't dare to ask the teacher, does he? 4.如果陈述句的谓语动词含有used to时,也可以有两种反意疑问句形式。例如: He used to live in London, usedn't/ didn't he? 5.如果陈述句中出现never, seldom, hardly, scarcely, rarely, few, little, nobody, no one, nothing等含有否定意义的词时,反意疑问句通常要用肯定式。例如: She seldom goes to the concert, does she? He has few good reasons for staying, has he? 6.如果陈述句中的主语是不定式短语、动名词短语、从句、everything或nothing时,反意疑问句通常要用it作主语。例如: To sell/ Selling newspaper was his job, wasn't it? What he said is true, isn't it? Everything is all right, isn't it? 7.如果陈述句中的主语是不定代词everybody, everyone, somebody, someone, nobody, no one, each of等时,反意疑问句通常要用they或he作主语。例如: Somebody borrowed my bike, didn't they/ he? Each of them passed the exam, didn't they?

Qt 的QString类的使用

Qt 的QString类的使用Qt的QString类提供了很方便的对字符串操作的接口。 1.使某个字符填满字符串,也就是说字符串里的所有字符都有等长度的ch来代替。 QString::fill ( QChar ch, int size = -1 ) 例: QString str = "Berlin"; str.fill('z'); // str == "zzzzzz" str.fill('A', 2); // str == "AA" 2,从字符串里查找相同的某个字符串str。 int QString::indexOf ( const QString & str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive ) const 例如: QString x = "sticky question"; QString y = "sti"; x.indexOf(y); // returns 0 x.indexOf(y, 1); // returns 10 x.indexOf(y, 10); // returns 10 x.indexOf(y, 11); // returns -1 3指定位置插入字符串 QString & QString::insert ( int position, const QString & str ) 例如: QString str = "Meal"; str.insert(1, QString("ontr")); // str == "Montreal" 3,判断字符串是否为空。 bool QString::isEmpty () const 如: QString().isEmpty(); // returns true QString("").isEmpty(); // returns true QString("x").isEmpty(); // returns false QString("abc").isEmpty(); // returns false

java 字符串常用函数及其用法

java中的字符串也是一连串的字符。但是与许多其他的计算机语言将字符串作为字符数组处理不同,Java将字符串作为String类型对象来处理。将字符串作为内置的对象处理允许Java提供十分丰富的功能特性以方便处理字符串。下面是一些使用频率比较高的函数及其相关说明。 String相关函数 1)substring() 它有两种形式,第一种是:String substring(int startIndex) 第二种是:String substring(int startIndex,int endIndex) 2)concat() 连接两个字符串 例:String s="Welcome to "; String t=s.concat("AnHui"); 3)replace() 替换 它有两种形式,第一种形式用一个字符在调用字符串中所有出现某个字符的地方进行替换,形式如下: String replace(char original,char replacement) 例如:String s=”Hello”.replace(’l',’w'); 第二种形式是用一个字符序列替换另一个字符序列,形式如下: String replace(CharSequence original,CharSequence replacement) 4)trim() 去掉起始和结尾的空格 5)valueOf() 转换为字符串 6)toLowerCase() 转换为小写 7)toUpperCase() 转换为大写 8)length() 取得字符串的长度 例:char chars[]={’a',’b’.’c'}; String s=new String(chars); int len=s.length(); 9)charAt() 截取一个字符 例:char ch; ch=”abc”.charAt(1); 返回值为’b’ 10)getChars() 截取多个字符 void getChars(int sourceStart,int sourceEnd,char target[],int targetStart) sourceStart 指定了子串开始字符的下标 sourceEnd 指定了子串结束后的下一个字符的下标。因此,子串包含从sourceStart到sourceEnd-1的字符。

相关文档
最新文档