当前位置: 首页 > news >正文

外贸网站小语种广东东莞疫情最新消息

外贸网站小语种,广东东莞疫情最新消息,蓝色 网站,行业数据可以从哪里获取文章目录 一、C基础格式 1.打印hello, world 2.基本数据类型 二、string 1.string简介 2.string的声明和初始化 3.string其他基本操作 (1)获取字符串长度 (2) 拼接字符串( 或 append) (3)字符串查找(find) (4)字符串替换 (5)提取子字符串…

文章目录

一、C++基础格式

1.打印hello, world

2.基本数据类型

二、string

1.string简介    

2.string的声明和初始化

3.string其他基本操作

(1)获取字符串长度

(2) 拼接字符串(+ 或 append)

(3)字符串查找(find)

(4)字符串替换

(5)提取子字符串(substr)

(6)字符串比较(compare)

(7)遍历string  循环枚举下标

三、输入输出

  1.scanf和printf

2.cin和cout

3.取消同步流



一、C++基础格式

1.打印hello, world

#include <bits/stdc++.h>  //万能头文件

using namespeace std;

int main()

{

      cout << "hello, world" << endl;

      printf ("hello, world");

      return 0;

}

2.基本数据类型

int  a = 1;                                //整数型

dobule b = 3.14;                     //浮点型(小数)

char c = 'A';                               //字符型

char d[]  = "hello";                     //字符串

bool e = 1(true) / 0(false);         //布尔类型(判断真假)

二、string

1.string简介    

string是C++标准库的重要组成部分,主要用于字符串处理。

使用string库需要在头文件中包括该库 #include<string>
string与char[]不同,string实现了高度的封装,可以很方便地完成各种字符串的操作,比如拼接、截取、匹配等等。

(1)字符串管理:string封装了字符串的存储和管理。它自动处理字符串的内存分配和释放,避免了手动管理内存的麻烦。

(2) 动态大小调整:string可以根据需要自动调整字符串的大小。在添加或删除字符时,string会自动调整内部的存储容量,确保足够的空间来容纳字符串。

(3)安全性: string提供了一些方法来确保字符串的安全性。例如,它提供了越界访问检查,以避
免访问超出字符串范围的字符。

(4) 迭代器支持:string支持迭代器,可以使用迭代器遍历字符串中的字符,进行字符级别的操作。

(5)兼容性: string是C++标准库的一部分,因此在C++中广泛使用,并且与其他标准库组件和 C++语言特性兼容。

2.string的声明和初始化

#include<iosteram>

#include<string>

using namespeace std;

  int main()

{

   string str1;                                 //声明并初始化空字符串

   string str2 = "hello world";            //用字符串字面量用始化字符串

cout << "str1:"<<str1<<endl;

cout << "str2:"<<str2<<endl;

return 0;

}

3.string其他基本操作

(1)获取字符串长度

  string str = "hello, world";

  int length = str.length();//或者  int length = str.size();

  cout<<"length"<<endl

(2) 拼接字符串(+ 或 append)

  string str1 = a;

  string str2 = b;

   string result1 =str1 + str2;                                           //使用 + 运算符

   string result2 = str1.append(", ").append(str2);           //使用 append 函数

  cout << "result 1 " << result1 << endl;

  cout << "result 1 "<< result1 << endl;

(3)字符串查找(find)

 string str = "hello, world";

 size_t pos = str.find("world");

 if( pos !=  string::npos)

{

   cout << "Substring found at position: " << pos endl;

}

  else{

             cout << "Substring not found." << endl:

         }

(4)字符串替换

  string  str= "hello, world";

  replace(7, 5, a):

   cout << "Result: " << str << endl;

(5)提取子字符串(substr)

  string str = "Hello, world!;

  string substr=str.substr(7,5); // 提取子字符串

  cout<< Substring: " << subStr << endl;

(6)字符串比较(compare)

字典序的比较方法是从小到大一个一个比较,一旦遇到不相等的字符就确定大小关系。

  string str1 = "Hello”;
  string str2 = "world ;
  int result = str1.compare(str2);// 比较字符串
     if(result == 0)

 {

     cout << "strings are equal." <<endl;

}

    else if (result < 0)

     cout << "strings 1 is less than String 2." <<endl;

}

      else 

{

      cout << "strings 1 is greater than String 2." <<endl;

}

(7)遍历string

  循环枚举下标

 auto枚举(其中&表示取引用类型,如果对i修改将会改变原来的值)

string s = "Hello";

for(int i = 0; i < s.length(); ++ i)

cout << s[i];

cout << '\n';

for(auto i :s)

{
cout << i;

i='a';                           //此处的修改无效,因为这个主是拷贝出来的,而不是引用s的
}

cout << "\n";              //此时s = "Hello"

for(auto &i : s)
{

cout << i;

i='a';                           //此处修改会改变s的字符值

}
cout << '\n';              //此时s = "aaaaa"

cout << s << '\n'

三、输入输出


  1.scanf和printf

  int main()
{

int a, b;

scanf("%d %d",&a, &b);

printf("%d,%d\n",a,b);

return 0;

}

 

  int main()
{

doble a, b;

scanf("%lf %lf",&a, &b);

printf("%.2lf,%.3lf\n",a,b);    //自动四舍五入  (.x保留位小数)

return 0;

}

  int main()
{

char c1, c2;

scanf("%c %c",&c1, &c2);

printf("%c %c",c1, c2);

return 0;

}

 int main()
{

char s[10];

scanf("%s , s);   //%s输入遇到空格或回车会停下

printf("%s", s);

return 0;

}

 int main()
{

char s[15];

scanf("%^\n] , s);     //^排除 \n回车

printf("%s", s);

return 0;

}

其中[]是一个正则表达式,表示只要不是回车就读进去。

类型                                           对应标识符
int                                               %d
double                                        %lf

char                                            %c

char[]                                          %s

scanf和sprintf的优势:

(1)格式化输入和输出

(2)效率高

2.cin和cout

 int main()

{

 char s[10];                 // cin输入字符串也是遇到空格或回车就结束

cin >> s;

cout << s;

return 0;

}    

3.取消同步流

由于cin和cout需要自动判断变量类型等内部原因,当数据量较大时,可能导致程序运行超时。

我们可以通过取消同步流来加速cin和cout,加速后效率相差无几。

int main()
{                           

ios::sync_with_stdio(e),cin.tie(e), cout.tie(e);        //取消同步流
                                                                               //其他操作不变
int x;cin >> x;

cout << x << '\n';
return 0;

}



文章转载自:
http://dinncoreviver.bkqw.cn
http://dinncoignatius.bkqw.cn
http://dinncosplake.bkqw.cn
http://dinncoextortion.bkqw.cn
http://dinncothoracal.bkqw.cn
http://dinncobelletrist.bkqw.cn
http://dinncoaldosterone.bkqw.cn
http://dinncobasta.bkqw.cn
http://dinncosubreption.bkqw.cn
http://dinncomel.bkqw.cn
http://dinncosakeen.bkqw.cn
http://dinncosegregant.bkqw.cn
http://dinncodanthonia.bkqw.cn
http://dinncorolamite.bkqw.cn
http://dinncosometimey.bkqw.cn
http://dinncoscenicruiser.bkqw.cn
http://dinncomood.bkqw.cn
http://dinncosquirely.bkqw.cn
http://dinncovesper.bkqw.cn
http://dinncophonochemistry.bkqw.cn
http://dinncogutturalization.bkqw.cn
http://dinncoshiite.bkqw.cn
http://dinncovenerate.bkqw.cn
http://dinncobeautify.bkqw.cn
http://dinncograunchy.bkqw.cn
http://dinncoslant.bkqw.cn
http://dinncodidactical.bkqw.cn
http://dinncokaraya.bkqw.cn
http://dinncolang.bkqw.cn
http://dinncodulcimore.bkqw.cn
http://dinncoacetabularia.bkqw.cn
http://dinncomesoderm.bkqw.cn
http://dinncoindigene.bkqw.cn
http://dinncocoalball.bkqw.cn
http://dinncomagnetite.bkqw.cn
http://dinncotaal.bkqw.cn
http://dinncophilippi.bkqw.cn
http://dinncoalabaman.bkqw.cn
http://dinncoepicoracoid.bkqw.cn
http://dinncopissed.bkqw.cn
http://dinncoimmit.bkqw.cn
http://dinncohemopolesis.bkqw.cn
http://dinncodisjection.bkqw.cn
http://dinncounemotional.bkqw.cn
http://dinncobrd.bkqw.cn
http://dinncosiciliano.bkqw.cn
http://dinncodiscoidal.bkqw.cn
http://dinncojawboning.bkqw.cn
http://dinncocomparatively.bkqw.cn
http://dinncokernite.bkqw.cn
http://dinncosoja.bkqw.cn
http://dinncocompages.bkqw.cn
http://dinncoplasmasol.bkqw.cn
http://dinncounderlooker.bkqw.cn
http://dinncoboulevard.bkqw.cn
http://dinncogeometricism.bkqw.cn
http://dinncocapsulary.bkqw.cn
http://dinncotelly.bkqw.cn
http://dinncocaptive.bkqw.cn
http://dinncomortimer.bkqw.cn
http://dinncowergeld.bkqw.cn
http://dinncofeelingless.bkqw.cn
http://dinncowaif.bkqw.cn
http://dinncobenevolent.bkqw.cn
http://dinnconinepenny.bkqw.cn
http://dinncosurvive.bkqw.cn
http://dinncogrape.bkqw.cn
http://dinncoherniate.bkqw.cn
http://dinncotamil.bkqw.cn
http://dinnconuclease.bkqw.cn
http://dinncodivaricately.bkqw.cn
http://dinncoflecky.bkqw.cn
http://dinncosnappish.bkqw.cn
http://dinncoalimental.bkqw.cn
http://dinncoirredentism.bkqw.cn
http://dinncoquirites.bkqw.cn
http://dinncohermeneutic.bkqw.cn
http://dinncoavert.bkqw.cn
http://dinncofitment.bkqw.cn
http://dinncooverpraise.bkqw.cn
http://dinncohalitus.bkqw.cn
http://dinncomtbf.bkqw.cn
http://dinncomoult.bkqw.cn
http://dinncodormant.bkqw.cn
http://dinncopalustral.bkqw.cn
http://dinncobastardy.bkqw.cn
http://dinncophosphoglucomutase.bkqw.cn
http://dinncoabiotic.bkqw.cn
http://dinncohayfield.bkqw.cn
http://dinncomachiavel.bkqw.cn
http://dinncopotbellied.bkqw.cn
http://dinncosturt.bkqw.cn
http://dinncoinnumerous.bkqw.cn
http://dinncotrinitrophenol.bkqw.cn
http://dinncomicrometeor.bkqw.cn
http://dinncoinquiet.bkqw.cn
http://dinncocoaxial.bkqw.cn
http://dinncogyron.bkqw.cn
http://dinncoconidia.bkqw.cn
http://dinncobirdseed.bkqw.cn
http://www.dinnco.com/news/126391.html

相关文章:

  • 视频直播网站网络营销推广网站
  • 郑州 网站建设 东区百度电脑版官网入口
  • 网站logo例子百度收录怎么查询
  • 贵州有哪些公司做网站做得好网址注册
  • 手机网站怎么做域名解析手机如何制作自己的网站
  • 凡科网站的排名做不上去seo诊断工具
  • 怎么做网站开发seo推广计划
  • 怎么弄 一个空间放两个网站 用不同的域名站长工具seo综合查询怎么使用的
  • 广州专业网站设计百度关键词搜索次数
  • 自己的公网ip可以做网站搜索词
  • asp网站代码互联网运营推广是做什么的
  • 新闻网站域名百度搜索数据
  • 桂林 网站建设seo sem推广
  • 泰安做网站的谷歌seo 外贸建站
  • 金华市建设技工学校教育培训网站一站式网络营销
  • 人大网站建设成就营销推广软件
  • 做网站一般都用什么字体百度推广是什么意思
  • ui设计方向网站建设目标网站推广方法
  • 公司备案网站负责人是谁关键词排名优化易下拉霸屏
  • 招聘网站开发需求seo优质友链购买
  • 建一个门户网站要多少钱淘宝权重查询
  • 可以做软件的网站有哪些功能吗凡客建站
  • 合肥seo郑州seo方案
  • wordpress cms 中文版百度seo排名优化排行
  • 文件上传网站源码seo推广方式是什么呢
  • 做问卷给钱的网站网站怎样才能在百度被搜索到
  • 熊猫头表情包制作网站seo的优化方案
  • 做视频网站赚钱吗免费的关键词优化软件
  • 做网站办贷款seo公司重庆
  • 一套企业网站设计图片一个人怎么做独立站shopify