C++的cout与C的printf之间的区别

来源:百度知道 编辑:UC知道 时间:2024/05/10 12:25:24
在C++中如何在一个字符串中打印变量?例如:
while(getline(in,s)!=false){
cout<<"This is line %d "<<i<<endl; //如何打在字符串中的变量?

//printf("This is number %d line\n", i);

i++;
}
C++的输出不能想C的printf打印变量,为什么?如何实现??

while(getline(in,s)!=false){
cout<<"This is line "<<i<<endl; //如何打在字符串中的变量?
这样就行了
入果你想打印多个变量就是这样
cout<<"the i is :"<<i<<" "<<"the j is :"<<j<<endl;
相当于
printf("the i is :%d the j is %d\n",i,j);

都一个意思把~~~cout好像是C++特有的