Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: C++11 and Code::Blocks  (Read 6075 times)

0 Members and 1 Guest are viewing this topic.

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
C++11 and Code::Blocks
« on: February 22, 2013, 08:29:50 am »
I can't seem to get my game to compile and run using C++11 features.

I have used the to_string() function in my code which is part of the C++11 standard.

I have told Code::Blocks to have g++ to follow C++11 ISO language standard and all I get is the following error:


I am using SFML 2.0-rc and I'm compiling with MinGW 4.6.2


Thanks. :)

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: C++11 and Code::Blocks
« Reply #1 on: February 22, 2013, 08:41:55 am »
With gcc 4.6 you have to use the -std=c++0x flag to enable support for c++11. -std=c++11 replaces that flag in version 4.7.
You could also update to 4.7, but keep in mind that you than have to recompile SFML.

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: C++11 and Code::Blocks
« Reply #2 on: February 22, 2013, 08:57:03 am »
Thanks, but now I just get this:


 ???

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: C++11 and Code::Blocks
« Reply #3 on: February 22, 2013, 09:03:21 am »
To me it look like you forgot the std:: namespace infront of to_string. But that's just a guess, because you don't show any code, so it's hard to tell...

Also you would have found the answer to both of your problems with a simple google search. Plaese google bofore you ask the next time you have a problem like that!

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: C++11 and Code::Blocks
« Reply #4 on: February 22, 2013, 09:16:16 am »
I was using namespace std; but I have also tried putting std:: in front of the to_string() function, this is the error it gives me:


Also if it helps, this is the function producing the error. Both cyanScore and redScore are sf::Text objects and score[0] and score[1] are integers.


:)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
AW: C++11 and Code::Blocks
« Reply #5 on: February 22, 2013, 09:27:00 am »
Unfortunetly std::to_string and a bunch of other functions don't work with MinGW yet.
For the official branche there's an unoffical patch, which can break some code (hacen't experienced any though): here.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: C++11 and Code::Blocks
« Reply #6 on: February 22, 2013, 09:35:39 am »
Oh right, I'm guessing that also means std::thread isn't supported yet either?

I'd rather just stick with the 'official' stuff for now. :)

As an estimate do you think to_string (and thread if it isn't supported yet) will be supported in 6 months time? or earlier?

Thanks for the responses, I really do appreciate the help.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: C++11 and Code::Blocks
« Reply #7 on: February 22, 2013, 09:50:17 am »
Found it in 2 seconds with Google. You should really start to use it.

http://gcc.gnu.org/projects/cxx0x.html
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
AW: C++11 and Code::Blocks
« Reply #8 on: February 22, 2013, 10:16:30 am »
There's also a 'patch' for std::thread, but if you really want it, you might grab the MinGW-w64 rubenvb experimental build, which has support for std::thread.

Also I'm not a dev for MinGw, nor MinGw-w64, nor GCC so I can't tell you an estimate. Also the various bug reports get only pushed around.
« Last Edit: February 22, 2013, 10:19:17 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: C++11 and Code::Blocks
« Reply #9 on: February 22, 2013, 10:29:46 am »
If you want to convert a number to a string you can use this template in the meantime:
#include <sstream>
#include <string>

template <typename T>
std::string toString(const T& value)
{
    std::ostringstream oss;
    oss << value;

    return oss.str();
}

sf::String text;
text.SetText("Score: " + toString(m_score));

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: C++11 and Code::Blocks
« Reply #10 on: February 22, 2013, 11:26:22 am »
@Laurent, I do know about Google. Though I really do prefer talking to people over forums, I get real responses and I can continue to ask questions and learn if I'm unsure about something. :)

@eXpl0it3r, I'll just stick with sf::Thread for now, It seems like the easiest option for me to compile on Mac and Windows at the moment.  :D

@Foaly, Thanks, I did know about the string stream, someone told me about it on here before and I had a similar idea to what you posted. :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: C++11 and Code::Blocks
« Reply #11 on: February 22, 2013, 11:32:42 am »
Quote
I do know about Google. Though I really do prefer talking to people over forums
Sure it's nicer to talk to real people, but you take the risk to annoy or even irritate people when the answer is already widely available on the internet.
Laurent Gomila - SFML developer

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: C++11 and Code::Blocks
« Reply #12 on: February 22, 2013, 12:11:35 pm »
I understand, I'll try and use Google more often. :)

 

anything