相关疑难解决方法(0)

在C++程序中使用scanf()比使用cin更快?

我不知道这是不是真的,但当我在其中一个问题提供网站上阅读常见问题时,我找到了一些东西,引起了我的注意:

检查输入/输出方法.在C++中,使用cin和cout太慢了.使用这些,您将保证无法通过适当的输入或输出解决任何问题.请改用printf和scanf.

有人可以澄清一下吗?真的在C++程序中使用scanf()比使用cin更快吗?如果是,那么在C++程序中使用它是一个好习惯吗?我认为这是C特定的,虽然我只是学习C++ ...

c c++ io performance

114
推荐指数
6
解决办法
7万
查看次数

快速输入输出功能

#define getcx getchar_unlocked
inline void inp( int &n )//fast input function
{
   n=0;
   int ch=getcx();int sign=1;
   while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();}

   while(  ch >= '0' && ch <= '9' )
           n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
   n=n*sign;
}
Run Code Online (Sandbox Code Playgroud)

嗨我一直在各种编码竞赛中使用上述功能输入,但从来没有能够理解为什么它很快.我知道逻辑,但不知道它的坚牢度的概念.例如,这行是做什么的"#define getcx getchar_unlocked".另外我不知道任何快速输出功能,所以还有任何快速输出功能

c c++ operating-system coding-style

5
推荐指数
1
解决办法
7261
查看次数

标签 统计

c ×2

c++ ×2

coding-style ×1

io ×1

operating-system ×1

performance ×1