C++ 允许用户输入名字和姓氏;向用户显示全名(第一个和最后一个)

C++ 允许用户输入名字和姓氏;向用户显示全名(第一个和最后一个),c++,arrays,char,C++,Arrays,Char,我知道这很简单,但我不知道我错过了什么或做错了什么。我想这可能是和char变量有关。这就是我到目前为止所做的: #include<stdio.h> #include "stdafx.h" #include<iostream> using namespace std; int main() { char fname[20],lname[20]; cout<<"Please enter your First Name:"; cin>>"fn

我知道这很简单,但我不知道我错过了什么或做错了什么。我想这可能是和char变量有关。这就是我到目前为止所做的:

#include<stdio.h> 
#include "stdafx.h"
#include<iostream>

using namespace std;

int main() 
{ 
char fname[20],lname[20];

cout<<"Please enter your First Name:";
cin>>"fname";
cout<<"Please enter your Last Name:";
cin>>"lname";

cout<<"Your full name is:"<<fname<<lname<<endl;

int a,b = 0;

for(a=0;a<=50;a++) 
{ 
if(a%3!=0&&a%4!=0&&a%5!=0) 
{ 
printf(" %d",a);
b++;
} 
} 
printf("\nNos of counts%d",b); 

} 
#包括
#包括“stdafx.h”
#包括
使用名称空间std;
int main()
{ 
char fname[20],lname[20];
cout“fname”;
cout“lname”;
库特
您正试图提取到字符串literal
“fname”
。似乎您想提取到变量
fname

cin>>fname;

因为约瑟夫回答了这个问题,所以我想提出一些建议。在名字和姓氏之间加一个空格,这样就不会把名字作为一个单词打印出来

cout <<"Your full name is: "<< fname << ' '  << lname << endl;

和CUT比Prtf强大得多,除非C++没有其他选项,否则不应该使用C语法。

cout << a << ' ';

cout我和爱因斯坦完全一样。如果可以的话,别忘了接受答案。谢谢,我把它们放进去了。程序末尾有一个21,有人知道如何摆脱它吗?int main(){char fname[20],lname[20];coutfname;coutlname;coutar你还遇到这个问题吗?
int a = 0, b = 0;
cout << a << ' ';
cout  << "\nNos of counts " << b;