Home >Backend Development >C++ >Why Does g (MinGW) Report 'to_string Not Found in std,' and How Can I Fix It?

Why Does g (MinGW) Report 'to_string Not Found in std,' and How Can I Fix It?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-23 18:13:17767browse

Why Does g   (MinGW) Report

to_string Not Found in std, Says g (Mingw)

Problem Statement

When compiling a C program that uses std::to_string() with g (MinGW 4.7.0), the compiler generates an error, stating "to_string is not a member of std."

Cause

This is a known bug in MinGW versions prior to GCC 4.8.0, specifically with the C 0x standard mode.

Solution

There are two main solutions to this issue:

1. Apply a Patch

Visit the bug report provided on Bugzilla (link in the provided answer) and download the patch to update MinGW. Install the patch and recompile your program.

2. Use an Updated MinGW Distro

Use a MinGW distro that supports GCC versions above 4.8.0. The following distros are known to have this issue resolved:

  • MinGW-w64 (versions higher than 4.8.0)
  • Nuwen MinGW

Install the updated MinGW distro and compile your program again.

Additional Notes

  • The to_string() function is part of the C 11 standard, which is enabled by the -std=c 0x flag in g .
  • MinGW versions prior to 4.8.0 have incomplete support for C 11 features.
  • For MinGW versions below 4.8.0, you may need to use an alternative method for converting long integers to strings, such as sprintf(), strftime(), or boost::lexical_cast.

The above is the detailed content of Why Does g (MinGW) Report 'to_string Not Found in std,' and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn