我的程序在请求输入期间一直显示多个输出,我该如何解决这个问题 [英] My program keeps on displaying multiple output during request for an input at a time how do I solve this
本文介绍了我的程序在请求输入期间一直显示多个输出,我该如何解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include< iostream.h>
class person
{
char name;
int age;
int 标记;
public :
void get_details( void ){
cout<< 输入学生姓名 跨度><< ENDL;
cin>> name;
cout<< 输入学生年龄<< endl;
cin>>年龄;
cout<<输入学生的标记<< endl;
cin>>标记
};
int main {
person p;
p.get_details();
return 0 ;
}
我的尝试:
对c#使用Console.ReadLine()方法但它不起作用
解决方案
C#的等效C#ReadLine
函数是 getline(string) - C ++参考a> [ ^ ]。
注意getline()
读入一个字符串。如果要将其与其他类型(如int
)一起使用,则必须读入临时字符串并将其转换为所需类型(例如atoato - C ++参考a> [ ^ ]或 strtol - C ++参考a> [ ^ ]int
)。
# include<iostream.h>
class person
{
char name;
int age;
int marks;
public:
void get_details(void){
cout<<"enter name of student"<<endl;
cin>>name;
cout<<"enter the age of student"<<endl;
cin>>age;
cout<<enter marks of student<<endl;
cin>>marks
};
int main{
person p;
p.get_details();
return 0;
}
What I have tried:
to use the Console.ReadLine() methord for c# but it does not work
解决方案
The C++ equivalent of the C#ReadLine
function is getline (string) - C++ Reference[^].
Note thatgetline()
reads into a string. If you want to use it with other types likeint
, you must read into a temporary string and convert that to the required type (e.g. atoi - C++ Reference[^] or strtol - C++ Reference[^] forint
).
这篇关于我的程序在请求输入期间一直显示多个输出,我该如何解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文