如何将char添加到char [1024]? [英] How do I add char to char[1024]?

查看:120
本文介绍了如何将char添加到char [1024]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>
#include <conio.h>
using namespace std;
int main(){
	char command[1024];
	char newchar;
	cout << "Command Line Interface Test with Intellisense" << endl;
	cout << endl;
	newchar = _getch();
	command = command + newchar;
}





为什么这不起作用?



为什么command = command + newchar是错误的?



Why does this not work?

Why command = command + newchar is wrong?

推荐答案

因为你试图在指针中添加一个字符。没有这样的操作。如果它被定义了,它意味着什么?



如果你期望数组大小应该增加,那将是不合逻辑的。您在堆栈上分配了1024个字符的空间,以及其他数据, newchar 的空间,依此类推。即使一个字符可以连接到数组,结果也会擦除堆栈上的其他数据。



你真的需要学习数组,指针,存储类型和其他基础知识。



-SA
Because you are trying to add a character to a pointer. There is no such operation. If it was defined, what would it mean?

If you expected that the array size is supposed to increase, it would be illogical. You allocated the room for 1024 characters on stack, along with other data, a room for newchar, and so on. Even of a character could "concatenate" to the array, the result would erase some other data on stack.

You really need to learn arrays, pointers, storage types and other basics things.

—SA


这篇关于如何将char添加到char [1024]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆