光标定位输出----‘\t'格式
#include <iostream>#include <windows.h>
#include "DoubleList.h"
#include <fstream>
using namespace std;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE); //获取句柄
void gotoxyWithFullwidth(int x,int y) //光标定位
{
COORD pos;
pos.X=x;
pos.Y=y;
SetConsoleCursorPosition(hOut,pos);
}
void output(int x,int y){
string name[3]={"成功者","失败地方","胆小鬼"};
gotoxyWithFullwidth(x,y);
cout<<"ID:"<<name[0]<<"\tname:"<<"zhang";
gotoxyWithFullwidth(x,y+1);
cout<<"ID:"<<name[1]<<"\tname:"<<"liu";
gotoxyWithFullwidth(x,y+2);
cout<<"ID:"<<name[2]<<"\tname:"<<"li";
}
int main(){ output(0,0); output(30,0); return 0;}
结果:
ID:成功者 name:zhang ID:成功者 name:zhang
ID:失败地方 name:liu ID:失败地方 name:liu
ID:胆小鬼 name:li ID:胆小鬼 name:li
为什么第二次调用ouput();数据却没有对齐;