【发布时间】:2012-12-16 08:32:48
【问题描述】:
下面是给出的代码,我已经让这个程序连接两个字符串连接,但是在显示连接后它不显示第一个单词.....我认为 cin.ignore() 中缺少一些东西请检查并帮帮我???
#include "stdafx.h"
#include<iostream>
#include <stdio.h>
#include <string>
#define MAX 100
using namespace std;
void main ()
{
char str[MAX],abc[MAX];
cout<<"\nEnter the string 1";
cin.ignore();
cin.get(str,MAX);
cout<<"\nEnter The String 2";
cin.ignore();
cin.get(abc,MAX);
cout<<"\nS1="<<str;
cout<<"\ns2="<<abc;
strcat(str,abc);
cout<<"\nStrings after catenation are"<<str;
system("pause");
}
这个程序的错误是连接后第一个字母没有显示在这一行cin.ignore();。另一个错误是我想将结果存储在另一个字符中说char d[MAX] 但编译器给出了错误
【问题讨论】:
标签: c++ concatenation