首页 > 其他分享 >关于 using namespace std

关于 using namespace std

时间:2023-05-29 18:23:39浏览次数:37  
标签:std cout int namespace using include

我刚接触c++,写Hello, World 是这个样子的

#include <bits/stdc++.h>
using namespace std;
int main()
{
     cout << "Hello, World" << endl;
     return 0;            
}

但是一直令我不解的是

using namespace std;

这东西这么麻烦写他干嘛?

今天我在写随机生成数据时发现了一位大佬写的(不知道网址了,还请大佬看见时与我联系)

#include <iostream>
#include <ctime>
#include <cstdlib>
 
int getRand(int min, int max);
 
int main() 
{

    
    freopen("test.txt","w",stdout);
    
    srand(time(0));
 
    for (int i=0; i<10; i++) 
    {
        int r = getRand(1, 100); // 生成数的区间在1 —— 100;
        std::cout << r << std::endl;
    }
 
   
}
    
    int getRand(int min, int max) 
    {
    return ( rand() % (max - min + 1) ) + min ;
    }

结果我定睛一看,这不就没写?

于是我上网一搜

"using namespace std;" 是 C++ 程序中常用的一个语句,它告诉编译器在当前程序中使用 "std" 命名空间中的符号。 "std" 是 C++ 标准库的缩写,里面包含了许多常用的函数和类型,如 cout、endl、string 等。使用 "using namespace std;" 可以省去在使用这些符号时前缀 "std::" 的麻烦。

得,不写更麻烦了呢,6。

 

标签:std,cout,int,namespace,using,include
From: https://www.cnblogs.com/Auditorymoon-yue/p/17441289.html

相关文章

  • 关于VBA的TextStream StdOut相关程序的学习——源代码(刘永富博士的ExcelVBA编程开发)
    Subtest3()'标准输出-查找相关目录下所有的GIF格式文件。DimTS1AsIWshRuntimeLibrary.TextStreamDimTS2AsIWshRuntimeLibrary.TextStreamSetWShell=NewIWshRuntimeLibrary.WshShellSetWE=WShell.Exec("cmd.exe/k")SetTS1=WE.StdInTS1.......
  • C#中使用using进行资源管理的的类型有哪些?
    在C#中,实现IDisposable接口的类型可以使用using语句进行资源管理,具体如下:1. System.IO.Stream:表示字节流的抽象类。它是所有文件I/O操作的基类,包括文件读取和写入。using(Streamstream=newFileStream("file.txt",FileMode.Open)){//使用stream对象进行文件读取操......
  • How to Control an External USB Web Camera Using a Raspberry Pi All In One
    HowtoControlanExternalUSBWebCameraUsingaRaspberryPiAllInOne如何使用树莓派控制外接USB网络摄像头USB网络摄像头罗技C270i高清网络摄像头(视频120万像素,照片300万像素)1280x720=>720P1280*720//921600不足100万,90万✅PCh......
  • Qt 中将std::cout 重定向到 qDebug
    #include<QtCore>#include<iostream>voidcustomMessageHandler(QtMsgTypetype,constQMessageLogContext&context,constQString&msg){QByteArraylocalMsg=msg.toLocal8Bit();switch(type){caseQtDebugMsg:......
  • 使用 PostMessage 函数来发送带有 std::vector 作为参数的消息
    使用PostMessage函数来发送带有std::vector作为参数的消息,您可以将std::vector的地址封装进LPARAM类型的指针中,并将其传递给PostMessage函数的lParam参数。在接收方,您需要使用reinterpret_cast将LPARAM转换回std::vector的指针,然后使用它来访问std::vector。下......
  • RustDesk,可私有部署的远程控制软件
    一、服务端:运行压缩包里面的RustDeskServer.Setup.exe安装即可  二、客户端:输入ID服务器IP地址即可开始连接,完全免费使用,无任何限制 ......
  • error CS0246: The type or namespace name ‘NetworkManager‘ could not be found
    项目场景:之前用Unity5.x开发的项目,要升级到Unity2019问题描述:因为项目中用到了老版的Network导致升级后报错errorCS0246:Thetypeornamespacename'NetworkManager'couldnotbefound(areyoumissingausingdirectiveoranassemblyreference?)<hrstyle="border:s......
  • Density estimation using Real NVP
    目录概MotivationRealNVPCouplinglayersDinhL,Sohl-DicksteinJ.andBengioS.Densityestimationusingrealnvp.ICLR,2017.概一种可逆的flow,感觉很diffusion已经非常非常像了.果然,伟大的成果从来不是一蹴而就的.Motivation\(x\)是原始数据,\(z\)......
  • 使用 TensorFlow 自动微分和神经网络功能估算线性回归的参数(Estimate parameters for
    大多数的深度学习框架至少都会具备以下功能:(1)张量运算(2)自动微分(3)神经网络及各种神经层TensorFlow框架亦是如此。在《深度学习全书公式+推导+代码+TensorFlow全程案例》——洪锦魁主编清华大学出版社ISBN978-7-302-61030-4这本书第3章《TensorFlow架构与主要功能》这一......
  • C#学习笔记 - using语句
    using语句某些类型的非托管对象有数量限制或很耗费系统资源,在代码使用完他们后,尽快释放他们是很重要的using语句有助于简化这一过程,并确保这些资源被适当的处理(0)资源指实现了System.IDisposable接口的类或结构.IDisposalbe接口中有个Dispose的方法,使用这个方法去处置......