string而非cstring

本文通过一个具体的程序实例展示了C++类库的强大功能。利用标准输入输出、字符串处理及集合操作等功能,实现了类的定义、查找等操作。该文深入探讨了C++编程语言中类与对象的概念,并通过实际代码演示了如何运用C++标准库来解决具体问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

c++的类库太强大了!给力!

#include<iostream> #include<cstdio> #include<string> #include<set> using namespace std; string cla="class",be="begin",end="end",sub="Sub",def="def",call="call",undef="undef"; string ch,t1,t2; set<string> duck; set<string>::iterator it;//迭代器 int main() { int t; int i,j,len,k; cin>>t; while(t--) { cin>>ch; while(ch.compare (end)!=0)//比较函数 { if(ch==be) {}; if(ch==cla) { cin>>t1; if(t1.at(3)==':') { len=t1.size (); t2=t1.substr (4,len-1);//复制 it=duck.find(t2); if(it==duck.end ()) { printf("oops!\n"); } else { /*printf("%s %s\n",ch.c_str() ,t1.c_str ());*/string 用printf输出 if(duck.count (t1)!=0) printf("oops!\n"); else { cout<<ch<<" "<<t1<<endl; duck.insert (t1); } } } else { if(duck.count (t1)==0) { cout<<ch<<" "<<t1<<endl; duck.insert (t1); } else printf("oops!\n"); } } if(ch==def) { cin>>t1; int point=t1.find ('.'); t2=t1.substr (0,point-1); if(duck.find (t2)==duck.end ()) printf("oops!\n"); else { if(duck.find (t1)==duck.end ()) { cout<<"def"<<" "<<t1<<endl; duck.insert (t1); } } } if(ch==call) { cin>>t1; } cin>>ch; } } return 0; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值