Was ist basic_string <TCHAR>?

Understood

Grünschnabel
Hallo, liebe Community von tutorials.de.

Ich habe mir ein kleines Skript aus dem Internet gesaugt, dass den momentanen Fenstertiteln ausliest.

Dieser Titel wird in die Variable "title" (ohne Anführungsstriche) gespeichert, der Variablentyp ist "basic_string <TCHAR>".
Was bedeutet das?

Die wichtige Programmierzeile:
Code:
    basic_string<TCHAR> title(bufsize, 0);

Der ganze Code:
Code:
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;

int main()
{
    HWND handle = GetForegroundWindow();
    int bufsize = GetWindowTextLength(handle) +1;
    basic_string<TCHAR> title(bufsize, 0);
    GetWindowText(handle, &title[0], bufsize);
    
    cout << title << endl << endl;
	system("PAUSE");
}

Vielen Dank für die Hilfe im Vorraus!

Mit freundlichen Grüßen,
Understood.
 
Hi.

TCHAR ist ein Windows-spezifischer Typ. Je nach Einstellung bedeutet er entweder "char" oder "wchar_t".

std::string ist ein typedef für std::basic_string<char>.

std::wstring ist ein typedef für std::basic_string<wchar_t>.

Demnach steht std::basic_string<TCHAR> entweder für std::string oder std::wstring. Je nach dem, ob Unicode oder ANSI verwendet werden soll.

PS: GetWindowText steht auch - je nach Einstellung - entweder für GetWindowTextA oder GetWindowTextW.
 
Zurück