|
查看: 1500|回复: 3
|
Arrays C++
[复制链接]
|
|
|
怎样可以把1-3的Character array放在弟4个?
请各位大大帮帮小弟。感激不尽!
=========================================================================
#include <iostream>
#include <cctype> //Needed for toupper function
#include <cstring> //Needed for string object
using namespace std;
int main()
{
char Name[10];
char No[7];
char Course[7];
char Output[24];
//Input from user
cout<< "Enter your first name: ";
cin>> Name;
cout<< "\nEnter your matric NO: ";
cin>> No;
cout<< "\nEnter your course: ";
cin>> Course;
//Store all the data
Output = Name + " - " + No + " - " + Course; <--Invalid
//Display data
for(int i=0;Output != '\0';i++)
Output= toupper(Output);
cout << Output << endl;
system("pause" ;
} |
|
|
|
|
|
|
|
|
|
|
发表于 11-8-2010 04:19 PM
|
显示全部楼层
|
c-string 那里可以用 +, 自己 google 一下 strcat |
|
|
|
|
|
|
|
|
|
|
发表于 17-8-2010 03:00 PM
|
显示全部楼层
本帖最后由 felixwlchuan 于 18-8-2010 09:10 AM 编辑
strcat 或sprintf
较高级点就用memcpy  |
|
|
|
|
|
|
|
|
|
|
发表于 31-12-2010 09:25 PM
|
显示全部楼层
|
都说是C++ 了, 为什么还用array? 那些人花如此多心血开发STL, 岂不是对不住他们? |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|