介绍一个插件 vscode,安装该工具需要进行配置
安装我们需要的插件;我们要开发c/c++的插件 创建文件夹,在文件夹下创建文件;如下图所示: 按下shift+ctrl+p,搜索Configure Task Runner;选择该选项然后点击“other”; 然后进行如下的配置
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "0.1.0", "command": "g++", "isShellCommand": true, "args": ["-g","main.cpp"], "showOutput": "always" }(1)保存字符串的方式
#include "stdafx.h" #include <stdlib.h> int _tmain(int argc, _TCHAR* argv[]) { //c语言里如何存储字符串 //方式一: char c1[]={'c','d','v','e'}; printf("%s\n",c1); //方式二: char c2[4]={'c','d','v','e'}; printf("%s\n",c2); //方式三: char c3[]="cdve"; printf("%s\n",c3); //方式四:字符串常量 char *p="cdve"; printf("%s\n",p); system("pause"); return 0; }字符常量不能修改
int _tmain(int argc, _TCHAR* argv[]) { //使用字符指针存储字符串,存放的是首地址 char *p="I love you!"; printf("%s\n",p); //此处报错,因为指针变量定义的是一个字符常量 *p='M'; system("pause"); return 0; }循环遍历打印字符串
int _tmain(int argc, _TCHAR* argv[]) { //使用字符指针存储字符串,存放的是首地址 char *p="I love you!"; while(*p){ printf("%c", *p); p++; } system("pause"); return 0; }字符串截取
int _tmain(int argc, _TCHAR* argv[]) { //使用字符指针存储字符串,存放的是首地址 char *p="I love you!"; //截取字符串,去掉I和空格 p=p+2; while(*p){ printf("%c", *p); p++; } system("pause"); return 0; }使用C语言提供的函数库