![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++基础知识
英俊大叔
这个作者很懒,什么都没留下…
展开
-
学习数组(二)
//Tips:cin会抓取用户输入的文字进入数组 然后逐个进行赋值 所以用户输入多个单词是会出现混乱#includeint main(){ using namespace std; const int ArSize=20; char name[ArSize]; char dessert[ArSize]; cout<<"Enter your name:\n";原创 2015-02-09 16:36:50 · 176 阅读 · 0 评论 -
数组、模板类vector对象、模板类array对象
#include #include #include int main(){ using namespace std; double a1[4]={1.2,2.4,3.6,4.8}; vector a2(4); a2[0]=1.0/3.0; a2[1]=1.0/5.0; a2[2]=1.0/7.0; a2[3]=1.0/9.0; array a3={3.14,2.72,原创 2015-03-19 16:10:15 · 399 阅读 · 0 评论 -
指针学习(四)
struct inflatable //结构定义{ char name[20]; float volume; double price;};int main(){ using namespace std; inflatable * ps=new inflatable;//给结构分配内存空间 cout<<"Enter name of inflatable it原创 2015-03-17 10:06:17 · 338 阅读 · 0 评论 -
指针学习(三)
#include #include int main(){ using namespace std; char animal[20]="bear"; const char * bird="wren"; char * ps; cout<<animal<<" and "; cout<<bird<<endl; //cout<<ps<<endl; cou原创 2015-02-12 17:38:02 · 297 阅读 · 0 评论 -
枚举类型学习
int main(){ using namespace std; enum spectrum{red,orange,yellow,green,blue,violet,indigo=100,ultraviolet}; //red、orange...这些第一个枚举量的值为0 第二个为1 可以显式的指定整数值来覆盖默认值 spectrum band; //band=3;不合法 i原创 2015-02-10 16:25:16 · 203 阅读 · 0 评论 -
指针学习(一)
#include "stdafx.h"#include int main(){ using namespace std; int updates=6; int *p_updates;//指针需要说明类型 p_updates=&updates; //两种取值的方法 cout<<"Value:updates="<<updates; cout<<",*p_up原创 2015-02-10 17:39:16 · 271 阅读 · 0 评论 -
共用体学习
#include struct widget{ char brand[20]; int type; union id //共用体 { long id_num; char id_char[20]; } id_val;};widget price;if (price.type==1){ cin>>price.id_val.id_num;原创 2015-02-10 14:49:08 · 223 阅读 · 0 评论 -
指针学习(二)指针与数组
#include int main(){ using namespace std; double wages[3]={10000.0,20000.0,30000.0}; short stacks[3]={3,2,1}; //取得内存地址 double * pw=wages;//double * pw= &wages[0];与这种写法是相同的 short * ps原创 2015-02-11 17:07:20 · 206 阅读 · 0 评论 -
结构学习(一)
//充气产品结构声明struct inflatable { char name[20]; float volume; double price; };//注意一定要添加;int main(){ using namespace std; //struct inflatable hat;创建结构变量 struct可以省略 inflatable gues原创 2015-02-10 11:41:57 · 208 阅读 · 0 评论 -
数组学习(三)
#include "stdafx.h"#include #include #include int main(){ using namespace std; /*没有string类之前的用法 strcpy(charr1,charr2);//将charr2的值赋值给charr1 strcat(charr1,charr2);//将charr2的值附加到charr1的原创 2015-02-10 10:25:27 · 321 阅读 · 0 评论 -
学习数组(一)
#includeint main(){ using namespace std; char dog[7]={'b','e','c','a','u',' ','2'}; cout<<dog; //测试是否能输出中间还有空字符的字符串 cin.get(); return 0;}//Tips:可以用以下的代码避免以上情况#includeint main原创 2015-02-09 14:43:47 · 265 阅读 · 0 评论 -
延迟循环
#include/* 等待你输入的系统时间为单位 之后进行下边的动作int main(){ using namespace std; cout<<"Enter the delay time, in secords: "; float secs; cin>>secs; clock_t delay=secs * CLOCKS_PER_SEC; cout<<"starting\a\n"原创 2015-03-24 07:38:49 · 329 阅读 · 0 评论