C++名字空间与包含头文件的方法

本文提供了几个使用C++编写的程序示例,包括输出标准问候语、读取并转换数字的进制形式、拼接字符串以及展示转义字符的用法。通过这些例子,读者可以了解到基本的C++语法特性及其应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>

using namespace std;

int main(int argc, char* argv[])

{

printf("Hello World!/n");

     cout << " hello! /n"

        << 8 << " World " <<endl;

      cin>>num;

      cout << "octal value: /n"

             <<oct<< num <<endl;

      cout << "dec value: /n"

             <<dec<< num <<endl;

      cout << "hex value: /n"

             <<hex<< num <<endl;

      cout << "non printing char(escape): /n"

             <<char(27)<<endl;

return 0;

}

 

#include <iostream.h>

int main(int argc, char* argv[])

{

 string s1,s2;
 string s3 = "Hello!";
 string s4("World! ");
 s2 = "Today!";
 s1 = s3 + " " + s4;
 s1 += "8";//Appending to a string
 cout << s1 + s2 + "!"<<endl;

printf("Hello World!/n");

     cout << " hello! /n"

        << 8 << " World " <<endl;

cout << "Hello! /n"

        <<" /b Hello World "

        <<"/b yy /b /n";

return 0;

}

 

#include <iostream>

int main(int argc, char* argv[])

{

printf("Hello World!/n");

std:: cout << "Input num "

             << 8 << " /b please " <<endl;

 

return 0;

}

名字空间与包含头文件的方法也是有关系的。如上红字,执行后,看到的效果是一样的。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值