Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use SFML without errors?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading