c++ - #include 的替代方案在 C++ 中
问题描述
为什么在用 C++ 编写程序时必须使用 iostream 库。如果我不想包含这个库,那么这个 iostream 库的替代方案是什么。
这是我的代码,不包括 iostream。我尝试使用 include stdio.h 但它不起作用。
#include<conio.h>
using namespace std;
void biodata ();
main()
{
biodata ();
}
void biodata()
{
cout << "Name: Ijlal Hussain.\nFather Name: Iftikhar Hussin.\nAge: 18. \nStudent of Comsats University Islamabad (Attock Campus)";
}
解决方案
如果您只需要输出文本,您可以使用<cstdio>
而不是。<iostream>
要打印不带格式的字符串,您可以使用puts
. 用于使用printf
格式和转换说明符进行打印。
#include<cstdio>
void biodata ();
int main()
{
biodata ();
return 0;
}
void biodata()
{
//using puts
puts("Name: Ijlal Hussain.\nFather Name: Iftikhar Hussin.\nAge: 18. \nStudent of Comsats University Islamabad (Attock Campus)");
//using printf
const char* name = "Ijlal Hussain";
const char* fathername = "Iftikhar Hussin";
int age = 18;
printf("Name: %s.\nFather Name: %s.\nAge: %d. \nStudent of Comsats University Islamabad (Attock Campus)", name, fathername, age);
}
推荐阅读
- powershell - 如何运行存储在 Powershell 变量中的类方法
- java - Spring boot,Jackson 在序列化中将空字符串转换为 NULL
- php - 将 CSV 上传到 MySQL 并定义列
- python - 使用 OpenCV detectMultiScale 找到最大的矩形
- javascript - 执行完最后一个函数后如何刷新页面?
- python - Box Python API - 如何将 SSL 证书检查设置为 false?
- perl - Perl:哈希切片不能在词法范围内
- google-chrome - 网站拒绝无头 chrome 连接
- angular - 如何在 Ng Select DropDown 上触发 keydown 事件 - 在后面的代码中获取 ng 选择面板
- vuejs2 - Vue.js 自动将 Web 组件转换为元素