嘿,我是编程的初学者。所以这听起来很愚蠢。但我真的不知道很多事情。我想编写一个程序,其中用户输入可以是数字或字符串/单词。如果是数字,则以某种方式处理;如果它是一个单词,它将以另一种方式处理。这意味着我想检查输入类型并根据它工作!我已经尝试过了,但它不起作用!
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
int number;
string word;
cout<<"enter a number or a word\n";
while(cin>>number || cin>>word){
if(cin>>number){
cout<<number<<"\n";}
if(cin>>word){
cout<<word<<"\n";}
}
return 0;
}