注册 登录
编程论坛 C语言论坛

关于wsprintf和outtextxy使用输出乱码的问题

Humiliation 发布于 2021-04-15 13:33, 1187 次点击
程序代码:
#include<stdio.h>
#include<iostream>
#include<graphics.h>
#include<easyx.h>
#include<string.h>
#include<stdlib.h>
#include<Windows.h>

using namespace std;
int main()
{
    initgraph(640, 500);
    wchar_t str[10];
    wsprintf(str, L"%s","aa" );
    outtextxy(0,0,str);
    system("pause");
}




在VC++2010中 为什么输出出来的是乱码?
2 回复
#2
Humiliation2021-04-15 13:37
是个小白,学校的实践周要求。很多内容都是网络上下来的,很多函数都没见过。。
#3
rjsp2021-04-15 14:03
#include<graphics.h>、initgraph(640, 500) 等~!@#$%我就不说了

wsprintf 这个MS的私有API是这么用的
程序代码:
#include <stdio.h>
#include <tchar.h>
#include <windows.h>

int main( void )
{
    {
        char str[10];
        wsprintfA( str, "%s", "aa" ); // 这是MS的,不是C++的
        puts( str );
    }
    {
        wchar_t str[10];
        wsprintfW( str, L"%s", L"aa" ); // 这是MS的,不是C++的
        _putws( str ); // 这是MS的,不是C++的
    }
    {
        TCHAR str[10]; // 这是MS的,不是C++的
        wsprintf( str, TEXT("%s"), TEXT("aa") ); // 这是MS的,不是C++的
        _putts( str ); // 这是MS的,不是C++的
    }
}


假如没有特殊的爱好,可以用C语言的标准函数,如
程序代码:
#include <stdio.h>

int main( void )
{
    {
        char str[10];
        sprintf( str, "%s", "aa" );
        puts( str );
    }
    {
        wchar_t str[10];
        swprintf( str, sizeof(str)/sizeof(*str), L"%s", L"aa" );
        fputws( str, stdout );
    }
}
1