My code for Text_Box.cpp is:
#include <SFML/Graphics.hpp>
int main1() {
sf::RenderWindow window(sf::VideoMode(800, 600), "Window",
sf::Style::Titlebar | sf::Style::Close);
sf::Font arial;
arial.loadFromFile("arial.ttf");
sf::Text t;
t.setFillColor(sf::Color::White);
t.setFont(arial);
std::string s = "This is text that you type: ";
t.setString(s);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
if (event.type == sf::Event::TextEntered) {
if (event.text.unicode < 128) {
s = static_cast<char>(event.text.unicode);
}
else {
// Time to consider sf::String or some other unicode-capable string
}
}
}
t.setString(s);
window.clear(sf::Color::Black);
window.draw(t);
window.display();
}
return 0;
}
I copied this above code to learn by changing commands from it. I am including it in my main file of c that is, main.c and using it at the very beginning of main function. My main.c code is:
#include <stdio.h>
#include "Text_Box.cpp"
int main() {
main1();
return 0;
}
but it is giving several errors like:
Severity Code Description Project File Line Suppression State
Error C4233 nonstandard extension used: '__is_final' keyword only supported in C , not C Project1 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits 543
Severity Code Description Project File Line Suppression State
Error C4233 nonstandard extension used: '__is_trivially_constructible' keyword only supported in C , not C Project1 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits 741
etc. I am using visual studio 2019. How can it be fixed? Is there something I am doing wrong? I have a doubt that do I need to compile SFML on my own as I am using visual studio 2019?
EDIT:
I tried without main.c file, renaming main1 to main and after adding additional dependencies, it is giving errors on executing:
sfml-graphic-d-2.dll
not found,
sfml-window-d-2.dll
not found,
sfml-system-d-2.dll
not found.
It also says reinstalling may fix this. So do I need to compile sfml as website of sfml mentions this?
CodePudding user response:
The compiler needs to specify (in the project settings)
/Zc:__cplusplus
Never do it bellow. Remove main.c and rename main1
to main
.
main.c
#include <stdio.h>
#include "Text_Box.cpp"
int main() {
main1();
return 0;
}