为什么printf首先比cout更有效 [英] why printf works first than cout

查看:113
本文介绍了为什么printf首先比cout更有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




这是一个代码。输出将是

为什么会这样。任何人都可以解释我这个..

4444 2222 7777 8888

aaaa


********* **********************

#include< stdio.h>

#include< iostream .h>


int main(无效)

{


char * test =" 4444 2222 7777 8888" ;;

cout<<"" aaaa";

printf(" New string:%s \ n",test);


返回0;

}

*********************** **********

谢谢


Pai ......

解决方案

pai写道:





这是一个代码。输出将是

为什么会这样。任何人都可以解释我这个..


4444 2222 7777 8888

aaaa


***** ************************** *

#include< stdio.h>

#include< iostream.h>


int main(无效)

{


char * test =" ; 4444 2222 7777 8888" ;;


cout<<" aaaa";

printf(" New string:%s \ n",测试);


返回0;

}

*************** ******************

谢谢


Pai ...


Cout是缓冲的,你没有将它与stdio同步(参见,例如,
http://www.cplusplus.com/ref/iostrea...th_stdio.html)


干杯! --M


pai写道:




这是一个代码。输出将是

为什么会这样。任何人都可以解释我这个..



您的标准库实现已经破坏。

cout和stdout应该是同步的一起

默认情况下。


当然,如果你使用的话,你没有使用标准库

cout ; iostream.h> ;.


尝试使用< iostreamand看看它是否更好。


mlimber写道:


Cout是缓冲的,你没有将它与stdio同步(参见,例如,
http://www.cplusplus.com/ref/iostrea...th_stdio.html)



sync_with_stdio在defualt中为真。


Hi,

This is a code . the output will be
why is this so. Can any nody explain me this..
4444 2222 7777 8888
aaaa

*******************************
#include <stdio.h>
#include<iostream.h>

int main(void)
{

char* test = "4444 2222 7777 8888";
cout<<"aaaa";
printf("New string: %s\n", test);

return 0;
}
*********************************
thanks

Pai...

解决方案

pai wrote:

Hi,

This is a code . the output will be
why is this so. Can any nody explain me this..
4444 2222 7777 8888
aaaa

*******************************
#include <stdio.h>
#include<iostream.h>

int main(void)
{

char* test = "4444 2222 7777 8888";
cout<<"aaaa";
printf("New string: %s\n", test);

return 0;
}
*********************************
thanks

Pai...

Cout is buffered, and you didn''t sync it with stdio (see, e.g.,
http://www.cplusplus.com/ref/iostrea...th_stdio.html).

Cheers! --M


pai wrote:

Hi,

This is a code . the output will be
why is this so. Can any nody explain me this..

Your standard library implementation is broken.
cout and stdout are supposed to be sync''d together
by default.

Of course, you''re not using a standard library
cout if you are using <iostream.h>.

Try it with <iostreamand see if it works better.


mlimber wrote:

Cout is buffered, and you didn''t sync it with stdio (see, e.g.,
http://www.cplusplus.com/ref/iostrea...th_stdio.html).

sync_with_stdio is true by defualt.


这篇关于为什么printf首先比cout更有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆