C++ #包括「;颜色;C+中的致命错误+;

C++ #包括「;颜色;C+中的致命错误+;,c++,C++,我试图编写一些类似康威的《生活游戏》的代码。一切似乎都很好,但我在“include.h”一词上犯了一个致命的错误。代码是C++的,我知道这个API属于C。我不知道它是否会产生区别,或者我必须使用C++的另一个API。原因是在我的台式电脑上,我不需要改变任何东西,程序运行得很好。但当我在另一台计算机上运行该程序时,它会在代码的第一行出现致命错误(#include“color.h”)。我不知道它为什么会出错 看 #包括“colors.h” #包括// #包括//setw() #包括//setCons

我试图编写一些类似康威的《生活游戏》的代码。一切似乎都很好,但我在“include.h”一词上犯了一个致命的错误。代码是C++的,我知道这个API属于C。我不知道它是否会产生区别,或者我必须使用C++的另一个API。原因是在我的台式电脑上,我不需要改变任何东西,程序运行得很好。但当我在另一台计算机上运行该程序时,它会在代码的第一行出现致命错误(#include“color.h”)。我不知道它为什么会出错

#包括“colors.h”
#包括//
#包括//setw()
#包括//setConsoleTitle(),Sleep()
#包括//rand(),seed()
#包括//cout
使用名称空间std;
//我们的数据和常数
const char LIFE='L';
常量字符空白=';
常数int N=20;
常数int M=20;
常数int NGRID=N*M;
char world[NGRID];//将模拟二维阵列。
内部位置(内部i、内部j)
{
返回i*M+j*sizeof(char);
}
void gotoxy(整数x,整数y,字符c)
{
世界[loc(x,y)]=c;
}
//我们处理数据的功能(即工具)
void fillWorldwith(字符w[],常量int N,常量int M,常量char stuff){

对于(int i=0;i您必须正确指定编译器的默认包含目录,或者将
colors.h
文件与其他文件放在同一目录中。

colors.h
不是标准的包含文件,因此问题是它在其他计算机上不可用。您需要安装提供该文件的软件它(如果是您自己创建的文件,则复制到那里)。

错误消息是什么?显示“colors.h”文件。这可能有用,因为我写的代码的第一行给出了一个致命错误。它还说没有这样的文件或目录。它找不到文件,请参阅下面的答案。请解决您的问题:文本和标题使用
color.h
,但代码使用
colors.h
。并检查英国拼写。
 #include "colours.h"
 #include <sstream>   //
 #include <iomanip>   // setw()
 #include <windows.h> // setConsoleTitle(), Sleep()
 #include <cstdlib>   // rand(), seed()
 #include <iostream>  // cout

 using namespace std;

 // OUR DATA and CONSTANTS
 const char LIFE  = 'L';
 const char BLANK = '.';

 const int N = 20;
 const int M = 20;
 const int NGRID = N*M;
 char world[NGRID];    // will simulate 2-dimenisonal array.

 int loc(int i, int j)
 {
   return i*M+j*sizeof(char);
 }

 void gotoxy(int x, int y, char c)
 {
  world[ loc(x,y)] = c;
 }

   // OUR FUNCTIONS (ie, TOOLS) that work on our DATA
  void fillWorldwith(char w[], const int N, const int M, const char stuff){
  for(int i=0; i<N; i++)
  for(int j=0; j<M; j++)
  w[loc(i,j)]=stuff;
 }

 void displayWorld(char *w, const int N, const int M){
 for(int i=0; i<N; i++)
 {
  for(int j=0; j<M; j++)
  cout << setw(2) << w[loc(i,j)];
  cout << endl;
 }
 }

  // Used in applyRules as a buffer to update world.
  void copyWorld(char dest[], char src[], const int N, const int M){

    for(int i=0; i<N; i++)
     for(int j=0; j<M; j++)
      dest[loc(i,j)]= src[loc(i,j)];
  }


int main()
{
  SMALL_RECT windowSize;                              // windows
  HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);  // windows

  windowSize = {0, 0, 200, 200};
  SetConsoleWindowInfo(hConsole, TRUE, &windowSize); // windows
  SetConsoleTitle("Game of Life");                   // windows

  system("cls");               // clear the console

  stringstream ss;  // trick to combine string and numbers
  ss << "color " << Black << Yellow;

  // objects are fun to use.
  system( ss.str().c_str() );   // change console colour

  fillWorldwith(world, N, M, BLANK);     // fill whole world with BLANKS
  displayWorld(world, N, M);
  int x=0, y =0;
   for(int time=0; time<100; time++){  // each loop, considered time.
   system("cls");
   displayWorld(world, N, M);              // display world
   gotoxy(x, y, BLANK);
   x= (x+1)%N;
   y= (y+1)%M;
   gotoxy(x, y, LIFE);
   Sleep(50);

  }

  return 0;
 }