出现error C2664: “textout”: 不能将参数 6 从“const char [17]”转换为“LPTSTR”怎样修改程序?
我用VS 2005出现错误error C2664: “textout”: 不能将参数 6 从“const char [17]”转换为“LPTSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
请高手帮忙改改
文件ColorConsole.h
#include <windows.h>
#include <iostream>
using namespace std;
HANDLE initiate();
BOOL textout(HANDLE hOutput,int x,int y,WORD wColors[],int nColors,LPTSTR lpszString);
文件colorConsole.cpp
#include "colorConsole.h"
HANDLE initiate()
{
HANDLE hOutput;
hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
return hOutput;
}
BOOL textout(HANDLE hOutput,int x,int y,WORD wColors[],int nColors,LPTSTR lpszString)
{
DWORD cWritten;
BOOL fSuccess;
COORD coord;
coord.X = x; // start at first cell
coord.Y = y; // of first row
fSuccess = WriteConsoleOutputCharacter(
hOutput, // screen buffer handle
lpszString, // pointer to source string
lstrlen(lpszString), // length of string
coord, // first cell to write to
&cWritten); // actual number written
if (! fSuccess)
cout<<"error:WriteConsoleOutputCharacter"<<endl;
for (;fSuccess && coord.X < lstrlen(lpszString)+x; coord.X += nColors)
{
fSuccess = WriteConsoleOutputAttribute(
hOutput, // screen buffer handle
wColors, // pointer to source string
nColors, // length of string
coord, // first cell to write to
&cWritten); // actual number written
}
if (! fSuccess)
cout<<"error:WriteConsoleOutputAttribute"<<endl;
return 0;
}
主文件 main.cpp
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include "colorConsole.h"
//投筛子
void rolldice(HANDLE hOutput,int n,int col,int row,WORD wColors[]);
void main(void)
{
HANDLE handle;
WORD wColors[1];
int row,col;
//初始化
handle = initiate();
//生成6个不同骰子
wColors[0]=FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY;
row=col=2;
for (int i=0;i<6;i++)
rolldice(handle,i+1,col,row+6*i,wColors);
//打印屏幕底部菜单
WORD wMenuColors[1];
wMenuColors[0]=FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY;
textout(handle,1,24,wMenuColors,1, "游戏规则:");
textout(handle,11,24,wMenuColors,1,"投掷开始/结束=ENTER;");
textout(handle,34,24,wMenuColors,1,"更换游戏者=空格;");
textout(handle,53,24,wMenuColors,1,"退出=q.");
bool flag=false;
int count=1;
int sum=0;
//随机数的种子
srand( (unsigned)time( NULL ));
col=15;
row=8;
//游戏开始
while(1)
{
if (_kbhit())
{
int ch=_getch();
if (ch==13)
{
flag=!flag;
if (!flag)
{
wColors[0]=FOREGROUND_RED|FOREGROUND_INTENSITY;
rolldice(handle,i+1,row,col,wColors);
//记录游戏者和点数
char buf[20];
itoa(count,buf,10);
textout(handle,1,13+2*count,wMenuColors,1,buf);
textout(handle,3,13+2*count,wMenuColors,1,"点数:");
sum+=i+1;
itoa(sum,buf,10);
textout(handle,9,13+2*count,wMenuColors,1,buf);
}
}
else if (ch==32)//更换游戏者
{
sum=0;
count++;
}
else if (ch=='q' || ch=='Q')
break;
}
if (flag)//随机投筛子
{
i=rand() % 6;
wColors[0]=FOREGROUND_RED|FOREGROUND_INTENSITY;
rolldice(handle,i+1,row,col,wColors);
Sleep(100);
wColors[0]=0;
rolldice(handle,i+1,row,col,wColors);
}
}
}
void rolldice(HANDLE hOutput,int n,int col ,int row,WORD wColors[])
{
switch(n){
case 1: textout(hOutput,row+1,col+1,wColors,1,"●");
break;
case 2: textout(hOutput,row+1,col, wColors,1,"●");
textout(hOutput,row+1,col+2,wColors,1,"●");
break;
case 3: textout(hOutput,row, col+2,wColors,1,"●");
textout(hOutput,row+1,col+1,wColors,1,"●");
textout(hOutput,row+2,col, wColors,1,"●");
break;
case 4: textout(hOutput,row, col, wColors,1,"●");
textout(hOutput,row, col+2,wColors,1,"●");
textout(hOutput,row+2,col, wColors,1,"●");
textout(hOutput,row+2,col+2,wColors,1,"●");
break;;
case 5: textout(hOutput,row, col, wColors,1,"●");
textout(hOutput,row, col+2,wColors,1,"●");
textout(hOutput,row+1,col+1,wColors,1,"●");
textout(hOutput,row+2,col, wColors,1,"●");
textout(hOutput,row+2,col+2,wColors,1,"●");
break;
case 6: textout(hOutput,row, col, wColors,1,"●");
textout(hOutput,row, col+1,wColors,1,"●");
textout(hOutput,row, col+2,wColors,1,"●");
textout(hOutput,row+2,col, wColors,1,"●");
textout(hOutput,row+2,col+1,wColors,1,"●");
textout(hOutput,row+2,col+2,wColors,1,"●");
break;
default:cout<<"投掷骰子失败!"<<endl;
}
}