优秀的编程知识分享平台

网站首页 > 技术文章 正文

C++知识点 1:输出 hello world.cpp

nanyue 2024-07-18 22:18:36 技术文章 8 ℃

// 标准输入输出流 i -- input; o -- output // 类似于C中 #include<stdio.h>
#include<iostream>
// 使用标准的命名空间
using namespace std;
/*
C 和 C++ 的头文件命名区别
C++ 中没有了扩展名 “.h” ,用前缀c代替,使之成为 C++ 风格
#include<time.h>
#include<ctime>
#include<math.h>
#include<cmath>
*/
int main()
{
printf("%s\n", "hello world"); // C 的标准输出
cout << "hello world" << endl; // C++ 的标准输出
// cout 是 c++ 中的标准输出流
// endl 是输出换行并刷新缓冲区
// << 左移运算符 在 C++ 中有了新的含义:拼接
// 这种输出方法可以避免区别各种类型及占位符
cout << 12345 << endl; // 整形
cout << 3.14 << endl; // 浮点型
cout << 'a' << endl; // 字符型
}


最近发表
标签列表