我有這樣的代碼:控制檯輸出笑臉
#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