关于C ++的问题.............. [英] Question about C++..............

查看:52
本文介绍了关于C ++的问题..............的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #include   <   iostream.h  >  
#include < conio.h >
#include < string.h >
void main()
{
clrscr();
char first [ 20 ];
char seond [ 20 ];
cout<< 输入字符串;
cin>> first;
strcpy(seond,first);
cout<< seond;
getch();
}



上面的代码是从第一个到第二个复制字符串

i想要显示输出为



ali ahmed



但是 stcpy function忽略空格后的字符。

解决方案

cin 不读取空格后的字符。如果您想要阅读多个单词,请使用 cin.getline()而不是 cin 。同步输入流。



 #include <   iostream.h  >  
#include < conio.h >
#include < string.h >
void main()
{
clrscr();
char first [20];
char seond [20];
cin.sync();
cout < <输入 string;



cin.getline(first,20);



strcpy(seond ,first);



cout<< seond;

getch();

}


#include <iostream.h>
#include <conio.h>
#include <string.h>
void main()
{
clrscr();
char first[20];
char seond[20];
cout<<"Enter string ";
cin>>first;
strcpy(seond,first);
cout<<seond;
getch();
}


The above code is from copying string from first to second
i want to display the output as

ali ahmed

but stcpy function ignores the characters after space.

解决方案

cin does not read characters after space. Use cin.getline() instead of cin if you want to read more than one word. Also sync the input stream.

#include <iostream.h>
#include <conio.h>
#include <string.h>
void main()
{
clrscr();
char first[20];
char seond[20];
cin.sync();
cout<<"Enter string";



cin.getline(first,20);



strcpy(seond,first);



cout<<seond;

getch();

}


这篇关于关于C ++的问题..............的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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