Skip to content

Instantly share code, notes, and snippets.

@ernestoalejo
Forked from anonymous/sss
Created April 23, 2012 17:25
Show Gist options
  • Save ernestoalejo/2472481 to your computer and use it in GitHub Desktop.
Save ernestoalejo/2472481 to your computer and use it in GitHub Desktop.
sss
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
#define TAMANIO_MAXIMO 0x1000
wstring ReadLine() {
const HANDLE stdIn = GetStdHandle(STD_INPUT_HANDLE);
WCHAR buffer[TAMANIO_MAXIMO];
DWORD numRead = 0;
if (!ReadConsoleW(stdIn, buffer, sizeof buffer, &numRead, NULL))
return wstring("");
const wstring line(buffer, numRead - 2);
return line;
}
void WriteLine(wstring line) {
const HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD numWritten = 0;
WriteConsoleW(stdOut, line.c_str(), line.size(), &numWritten, NULL);
}
int main()
{
wstring palabra(ReadLine());
// Usa WriteLine() solo si quieres imprimir un objeto wstring, en
// lugar del cout normal que usarás para el resto de cadenas
// (las cadenas con acentos que compiles irán bien)
WriteLine(palabra);
if(palabra == L"España")
cout << "es igual" << endl;
else
cout << "mal" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment