Thread: Convert a string to a char?

  1. #16
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Show the code where you tried to use the function and post the complete error message exactly as they appear in your development environment.

    Jim

  2. #17
    Registered User
    Join Date
    Jan 2011
    Posts
    101
    Code:
            getline(jcin, ask, '#');
    //rg = stoi(ask);
            istringstream (ask)>>rg;
            cout<<endl<<endl<<"Players rapid play grade : "<<rg;
    This is where I am trying it, 'ask' is being read from a text file and as written it works as it should, if I uncomment the line and comment out the istringstream line instead I get the following error:

    error : 'stoi' was not declared in this scope

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Post your full code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Then I would say your compiler doesn't support that feature. Stick to the stringstream solution. Or use atoi()
    Code:
    rg=atoi(ask.c_str());
    Jim

  5. #20
    Registered User
    Join Date
    Jan 2011
    Posts
    101
    Hi Elysia, do you mean the full 550 program or just the function?

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Your program. If it's 550 lines long, then make the smallest possible example that demonstrates the error.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Registered User
    Join Date
    Jan 2011
    Posts
    101
    That is what I did with the snippet I posted above, it works as it should using 'istringstream' but not if you use 'stoi'

    Probably not worth going further with this, I think Jim may well be right that my ompiler doen's have that functionality yet; I will have to look at upgrading but hven't a clue how to go about it! Do you think if I uninstalled Code::Blocks and re-installed the latest cersion that would do it? I am using v10.05. I know that is only the IDE but it installed gcc/mingw along with it when I first installed it.

  8. #23
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No. Go explore for mingw in your c::b directory.
    When you find it, go download latest mingw and install it into that directory (it would be called mingw or something).

    OK, so let me rephrase what I said above:
    Show us the smallest possible compilable example that reproduces the issue.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    That is what I did with the snippet I posted above, it works as it should using 'istringstream' but not if you use 'stoi'
    No that "snippet" will not compile as presented. You need to have at least a function main() to have a complete program, along with at least a couple of include files.

    Jim

  10. #25
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by JayCee++
    in the help files it says 4.5/6
    Is that "4.5.6" or "4.5 or 4.6"? My copy of g++ 4.6.3 comes with a standard library implementation that does have std::stoi.

    EDIT:
    Wait, there is no 4.5.6, yet.
    Last edited by laserlight; 07-03-2012 at 11:57 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #26
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    After retesting with g++ version 4.5.2 and insuring the -std=c++0x was selected stoi() was properly recognized.


    Jim
    Last edited by jimblumberg; 07-03-2012 at 11:58 AM.

  12. #27
    Registered User
    Join Date
    Jan 2011
    Posts
    101
    The latest mingw is 4.7 as far as I can make out and I appreciate this is probably not the right place to ask but can anyone tell me where to download an installable copy for windows and how to relace the version I have. I looked on google but only seem to be able to find tar files which I don't know what to do with?

  13. #28
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #29
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Another MinGW-Like GCC is TDM build of MinGW GCC; version 4.6.1 is the newest on the site.

    TDM-GCC

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Convert string to char or use 2d array of char?
    By simpleblue in forum C++ Programming
    Replies: 6
    Last Post: 09-25-2011, 05:00 PM
  2. Replies: 11
    Last Post: 06-16-2011, 11:59 AM
  3. Replies: 2
    Last Post: 09-12-2010, 09:15 AM
  4. Convert string to char[200]
    By maxorator in forum C++ Programming
    Replies: 4
    Last Post: 08-22-2005, 01:01 PM
  5. String Convert to Char ?
    By eko-eko in forum Windows Programming
    Replies: 2
    Last Post: 07-08-2002, 01:06 PM