控制台输出笑脸 [英] console outputs smiley face

查看:1285
本文介绍了控制台输出笑脸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

#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;
}



我不知道为什么我得到一个笑脸,而不是第一个数组元素!我在这里做错了什么?它编译并运行良好,但输出是

I wonder why am I getting a smiley face instead of the first array element! what am I doing wrong here? It compiles and runs fine however the output is


第一个数组元素:smiley face

first array element: "smiley face"

这是什么意思?
我使用Visual Studio 2010.感谢

What does this means? I am using Visual Studio 2010. Thanks

推荐答案

到目前为止,第一个数组元素。但是,您正在打印第二个(数组索引从0开始,而不是1)。第二个元素是2.现在,请查看这个表格,你可以看到:数字2是一个笑脸。问题是,你输出一个字符代码2,而不是'2'。为了输出一个deuce,使你的数组​​看起来像这样:

As far, as I can see, you are trying to output the first array element. But instead, you are printing the second one (the arrays are indexed starting from 0, not 1). The second element is 2. Now, please, take a look at this table, as you can see: the number 2 is a smiley face. The problem is that you are outputing a character with code 2, not '2'. In order to output a deuce, make your array look like this:

char arr[3] = {'1','2','3'};

这篇关于控制台输出笑脸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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