Dzień dobry,
Mam problem z VS 2019/2022. Otóż gdy tworzę projekt, tylko kilka razy uruchamia się on poprawnie. Zauważyłem, że często pojawiają się problemy jakiś czas po dodaniu swojego pliku *.h, dokładniej przy pisaniu kodu konstruktora.
Screen błędu:
No jeszcze tak na marginesie dziwię się, dlaczego VS nie stworzy po prostu tego pliku *.exe jak np. Code::Blocks.
Kod:
#include "pola.h"
int main()
{
setlocale(LC_CTYPE, "Polish");
//set_color("yellow");
cout << "Pomoc:" << endl;
cout << "Kolory pól:" << endl;
cout << "zielony - kólko,\nczerwony - krzyżyk,\nbiały - puste" << endl << endl;
set_color("white");
Pole p1(2);
p1.rysuj();
system("pause");
return 0;
}
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <algorithm>
#include <string>
using namespace std;
int runda;//1 - kółko, 2 - krzyżyk
class Pole
{
public:
int kto; //kto stoi? 0 - nikt, 1 - kółko, 2 - krzyzyk
void rysuj();//narysuj pole
Pole(int k);
};
void set_color(string color);
#include "pola.h"
#include <cstdlib>
void set_color(string color)
{
transform(color.begin(), color.end(), color.begin(), ::tolower);
if (color == "black")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 1);
else if (color == "green")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
else if (color == "blue-green")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 3);
else if (color == "red")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
else if (color == "green")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
else if (color == "gray")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
else if (color == "yellow")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
else if (color == "white")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
else
cout << "error";
}
void Pole::rysuj()
{
if (kto == 1 /*|| runda == 1 */ )
{
set_color("green");
for (int i = 0; i < 4; ++i)
{
for (int i = 0; i < 4; ++i)
{
cout << "* ";
}
cout << endl;
}
}
else if (kto == 2 /*|| runda == 2 */)
{
set_color("red");
for (int i = 0; i < 4; ++i)
{
for (int i = 0; i < 4; ++i)
{
cout << "* ";
}
cout << endl;
}
}
}
Pole::Pole(int k)
{
kto = k;
}
Proszę o pomoc.