主题:新手求助,哪位好心人帮我看一下编译错误??
--------------------Configuration: Console - Win32 Debug--------------------
Compiling...
console.cpp
D:\Program Files\Microsoft Visual Studio\MyProjects\Console\console.cpp(6) : error C2320: expected ':' to follow access specifier 'type'
执行 cl.exe 时出错.
Console.exe - 1 error(s), 0 warning(s)
源程序如下:
#include <afxcoll.h> //Provides Access to MFC functions
class CDrawBox : public CObject
{
public
// Draws the box.
void DoDraw(char * string);
}
void CDrawBox :: DoDraw(char* cValue)
{
int iCount; //Loop counter
int iSpace; //Amount of spaces to add for string.
// Draw the top of the box
fprintf(stdout,"\311");
for (iCount = 1; iCount <= 78 ; iCount ++)
{
fprintf(stdout,"\315");
}
fprintf(stdout,"\273");
// Figure out the center of the string, then display it
// with the box sides.
iSpace = (80 - strlen(cValue)) / 2;
fprintf(stdout,"\272");
for (iCount = 1; iCount <= iSpace ; iCount ++)
{
fprintf(stdout," ");
}
fprintf(stdout, "%s", cValue);
// Compensate for odd sized strings, then complete the side.
if ((strlen(cValue) % 2) == 1)
{
iSpace--;
}
for (iCount = 1; iCount <= iSpace ; iCount ++)
{
fprintf(stdout, " ");
}
fprintf(stdout,"\272");
// Draw the bottom of the box
fprintf(stdout, "\310");
for (iCount = 1; iCount <= 78 ; iCount ++)
{
fprintf(stdout, "\315");
}
fprintf(stdout, "\274\n");
}
int main(int argc, char ** argv)
{
char * cName; // Name of person typed at command line.
char * cLocale; // Program execution location.
CTime oMyTime; // A time object.
CString cDate; // String used to hold time and date.
CDrawBox oMyDraw; // Special text display.
// See if we have enough command line arguments.
if ( argc != 2)
{
fprintf(stderr, "Type the program name followed by your name.\n");
return 1;
}
// Get the command line arguments
cLocale = argv[0];
cName = argv[1];
// Get the current time and put it in a string.
oMyTime = CTime::GetCurrentTime();
cDate = oMyTime.Format( "%A, %B %d,%Y" );
//Display everything we've collected.
fprintf(stdout, "Hello %s\n\n", cName);
fprintf(stdout, "Program is executing from: \n%s\n\n", cLocale);
fprintf(stdout, "The date is: %s\n", cDate);
// Use our class to draw a box around some text.
oMyDraw.DoDraw("It's a Box!");
return 0;
}
Compiling...
console.cpp
D:\Program Files\Microsoft Visual Studio\MyProjects\Console\console.cpp(6) : error C2320: expected ':' to follow access specifier 'type'
执行 cl.exe 时出错.
Console.exe - 1 error(s), 0 warning(s)
源程序如下:
#include <afxcoll.h> //Provides Access to MFC functions
class CDrawBox : public CObject
{
public
// Draws the box.
void DoDraw(char * string);
}
void CDrawBox :: DoDraw(char* cValue)
{
int iCount; //Loop counter
int iSpace; //Amount of spaces to add for string.
// Draw the top of the box
fprintf(stdout,"\311");
for (iCount = 1; iCount <= 78 ; iCount ++)
{
fprintf(stdout,"\315");
}
fprintf(stdout,"\273");
// Figure out the center of the string, then display it
// with the box sides.
iSpace = (80 - strlen(cValue)) / 2;
fprintf(stdout,"\272");
for (iCount = 1; iCount <= iSpace ; iCount ++)
{
fprintf(stdout," ");
}
fprintf(stdout, "%s", cValue);
// Compensate for odd sized strings, then complete the side.
if ((strlen(cValue) % 2) == 1)
{
iSpace--;
}
for (iCount = 1; iCount <= iSpace ; iCount ++)
{
fprintf(stdout, " ");
}
fprintf(stdout,"\272");
// Draw the bottom of the box
fprintf(stdout, "\310");
for (iCount = 1; iCount <= 78 ; iCount ++)
{
fprintf(stdout, "\315");
}
fprintf(stdout, "\274\n");
}
int main(int argc, char ** argv)
{
char * cName; // Name of person typed at command line.
char * cLocale; // Program execution location.
CTime oMyTime; // A time object.
CString cDate; // String used to hold time and date.
CDrawBox oMyDraw; // Special text display.
// See if we have enough command line arguments.
if ( argc != 2)
{
fprintf(stderr, "Type the program name followed by your name.\n");
return 1;
}
// Get the command line arguments
cLocale = argv[0];
cName = argv[1];
// Get the current time and put it in a string.
oMyTime = CTime::GetCurrentTime();
cDate = oMyTime.Format( "%A, %B %d,%Y" );
//Display everything we've collected.
fprintf(stdout, "Hello %s\n\n", cName);
fprintf(stdout, "Program is executing from: \n%s\n\n", cLocale);
fprintf(stdout, "The date is: %s\n", cDate);
// Use our class to draw a box around some text.
oMyDraw.DoDraw("It's a Box!");
return 0;
}

您所在位置: