学习C++第一周
**C++基本内容 **
A
C++与 C基本格式
B
string 函数
一
关于C ++基本的格式
#include
using namespace std;
int main()
{
string a;
cin>>a;
cout<<a;
}
与C 比较
#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
printf("%d",a);
}
1
开头 #include< iostream>
using namespace std;
2
定义变量 使用 string
3
输入使用 cin>>a;
输出使用 cout<<a;
4
endl 相当于c 中 \n
5
C++ 现在感觉较 C 好用方便是 C++ 里面 包涵很多常用的函数 可以直接调用不像c 那样需要自己编写一些函数
6
使用 函数要写包涵它的函数 如使用 string 函数时 要写
#include
7
了解的一些 string 函数
(1 ) swap()
交换函数 使用时可以直接交换定义变量的值;
(2) length ()
字符串长度函数
(3) reverse()
字符串反转函数;
(4)find()
查找函数 返回时string ::npos;
( 5 ) insert ( )
可以实现插入功能
(6)replace ()
可以实现替换功能
(7)at()
可以修改字符串内字符 为某个 字符;