新手启示者
很复杂,可以用
int getch();
const int shift=25,ctrl=26,esc=27,_left=28,_down=29,_right=30,_up=31;
const string endline="\n";
struct os{stringstream ss;void present();};
template<class T>
os&operator <<(os&o,T a);
os out;
struct is{stringstream ss;};
is in;
template<class T>
is&operator >>(is&i,T&a);
void cls2(){
out.ss.clear();
}
template<class T>
os&operator <<(os&o,T a){
o.ss<<a;
return o;
}
template<class T>
is&operator >>(is&i,T&a){
char c;
string s;
if(i.ss){
while((c=getch())!=' '){
s+=c;
out<<c;
out.present();
window.present();
}
out<<" ";
i.ss<<s<<" ";
}
i.ss>>a;
return i;
}
void os::present(){
string a,s;
int i=0,j=0;
while(ss){
a+=ss.get();
j++;
Color fontColor={255,255,255,0};
if(!ss){
a=a.substr(0,a.size()-1);
window.drawText(a.c_str() , 20 , fontColor , 0 , i*20);
s+=a;
}
else if(j>=40){
window.drawText(a.c_str() , 20 , fontColor , 0 , i*20);
i++;
s+=a;
a="";
j=0;
}else
if(a[a.size()-1]=='\n'){
a=a.substr(0,a.size()-1);
window.drawText(a.c_str() , 20 , fontColor , 0 , i*20);
i++;
j=0;
s+=a;
s+="\n";
a="";
}
}
ss.clear();
ss<<s;
}
int getch(){
Event ev;
while(1){
sleep(1);
if(pollEvent(&ev)){
if(ev.type==CDT_KEYDOWN){
switch(ev.keyCode){
case CDT_KEY_0:
return'0';
case CDT_KEY_1:
return'1';
case CDT_KEY_2:
return'2';
case CDT_KEY_3:
return'3';
case CDT_KEY_4:
return'4';
case CDT_KEY_5:
return'5';
case CDT_KEY_6:
return'6';
case CDT_KEY_7:
return'7';
case CDT_KEY_8:
return'8';
case CDT_KEY_9:
return'9';
case CDT_KEY_a:
return'a';
case CDT_KEY_b:
return'b';
case CDT_KEY_c:
return'c';
case CDT_KEY_d:
return'd';
case CDT_KEY_e:
return'e';
case CDT_KEY_f:
return'f';
case CDT_KEY_g:
return'g';
case CDT_KEY_h:
return'h';
case CDT_KEY_i:
return'i';
case CDT_KEY_j:
return'j';
case CDT_KEY_k:
return'k';
case CDT_KEY_l:
return'l';
case CDT_KEY_m:
return'm';
case CDT_KEY_n:
return'n';
case CDT_KEY_o:
return'o';
case CDT_KEY_p:
return'p';
case CDT_KEY_q:
return'q';
case CDT_KEY_r:
return'r';
case CDT_KEY_s:
return's';
case CDT_KEY_t:
return't';
case CDT_KEY_u:
return'u';
case CDT_KEY_v:
return'v';
case CDT_KEY_w:
return'w';
case CDT_KEY_x:
return'x';
case CDT_KEY_y:
return'y';
case CDT_KEY_z:
return'z';
case KEY_UP:
return 31;
case KEY_RIGHT:
return 30;
case KEY_LEFT:
return 28;
case KEY_DOWN:
return 29;
case KEY_SPACE:
return 32;
case KEY_BACKSPACE:
return '\b';
case KEY_CTRLUP:
case KEY_CTRLDOWN:
return 26;
case KEY_ESCAPE:
return 27;
case KEY_SHIFTUP:
case KEY_SHIFTDOWN:
return 25;
}
}
}
}
}
解决