Like Tree2Likes

Convert a string to a char?

This is a discussion on Convert a string to a char? within the C++ Programming forums, part of the General Programming Boards category; Show the code where you tried to use the function and post the complete error message exactly as they appear ...

  1. #16
    Registered User
    Join Date
    May 2010
    Posts
    2,693
    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
    96
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    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
    2,693
    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
    96
    Hi Elysia, do you mean the full 550 program or just the function?

  6. #21
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    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
    96
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    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
    2,693
    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
    21,414
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #26
    Registered User
    Join Date
    May 2010
    Posts
    2,693
    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
    96
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    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
    2,510
    Another MinGW-Like GCC is TDM build of MinGW GCC; version 4.6.1 is the newest on the site.

    TDM-GCC

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

Page 2 of 2 FirstFirst 12
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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21