我有这样的代码:控制台输出笑脸
#include "stdafx.h"
#include <iostream>
typedef struct{
int s1;
int s2;
char c1;
char* arr;
}inner_struc;
int _tmain(int argc, _TCHAR* argv[])
{
inner_struc myinner_struct;
myinner_struct.s1 = myinner_struct.s2 = 3;
myinner_struct.c1 = 'D';
char arr[3] = {1,2,3};
myinner_struct.arr = arr;
std::cout << "first array element: " << myinner_struct.arr[1] << std::endl;
return 0;
}
我不知道为什么我会得到一个笑脸,而不是第一个数组元素!我在这里做错了什么?它编译和但是输出
第一个数组元素运行良好:“笑脸”
这是什么意思? 我正在使用Visual Studio 2010.谢谢
'char arr [3] = {1,2,3};'不是字符''1''''2' ''''3'',但不可打印的'\ 0x01','0x02','\ 0x03'。此外,对字符串使用'std :: string' – crashmstr 2014-09-12 19:26:12