cout与printf
下面这个程序不能正常运行:
#include <string.h>
#include <stdio.h>
#include <iostream.h>
void main()
{
const int MAX = 20 ;
char str_a[MAX] ;
char str_b[MAX] ;
cout << "please input the first string:" ;
gets(str_a) ;
cout << "please input the second string:" ;
gets(str_b) ;
char *pa ;
char *pb ;
for (pa = str_a , pb = str_b ; pa < str_a + strlen(str_a) && pb < str_b + strlen(str_b) ;
pa++ , pb++)
{
if (*pa == *pb)
{
cout << *pa ;
}
}
cout << endl ;
}
如果把上面的cout << "please input the first string:" ;cout << "please input the second string:" ;输出换成printf就可以正常运行,那位知道是什么原因啊,可能涉及到cout与printf的区别,
#include <string.h>
#include <stdio.h>
#include <iostream.h>
void main()
{
const int MAX = 20 ;
char str_a[MAX] ;
char str_b[MAX] ;
cout << "please input the first string:" ;
gets(str_a) ;
cout << "please input the second string:" ;
gets(str_b) ;
char *pa ;
char *pb ;
for (pa = str_a , pb = str_b ; pa < str_a + strlen(str_a) && pb < str_b + strlen(str_b) ;
pa++ , pb++)
{
if (*pa == *pb)
{
cout << *pa ;
}
}
cout << endl ;
}
如果把上面的cout << "please input the first string:" ;cout << "please input the second string:" ;输出换成printf就可以正常运行,那位知道是什么原因啊,可能涉及到cout与printf的区别,
...全文
相关推荐
printf和cout的比较.pdf
描述C++语法的关键用法,以及注重点和技巧,方便开发人员减少跳坑。
c++中cin/cout与scanf/printf的区别比较
主要介绍了c++中cin/cout与scanf/printf的区别比较,需要的朋友可以参考下
printf与cout区别[代码]
本文详细探讨了C++中cout与C语言中printf的区别及其背后的实现机制。文章首先指出cout和cin在C++中的常见用法,并解释其通过运算符重载实现输出的原理。通过代码示例展示了cout如何通过重载operator<<函数处理不同类型的数据输出,并分析了返回this指针以实现连续输出的机制。此外,文章对比了endl与 的不同,强调endl不仅换行还会刷新缓冲区,并详细介绍了缓冲区刷新的几种条件(如缓冲区满、程序结束等)。最后,文章总结了iostream库相比stdio库的优势,包括类型安全、扩展性强以及流风格的自然简洁。
C/C++输出彩色文字printf和cout显示的文字是彩色的有颜色的
C/C++输出彩色文字printf和cout显示的文字是彩色的有颜色的
基于对话框例子程序,MFC调用控制台,利用cout、printf输出信息
基于对话框例子程序,MFC调用控制台,利用cout、printf输出信息


新手乐园
