C++.NET Can I use atoi ??

This is a discussion on C++.NET Can I use atoi ?? within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm trying to learn C++.NET and I've got a listbox with some items in it via Properties->Collection. They're strings ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    30

    Question C++.NET Can I use atoi ??

    Hi,

    I'm trying to learn C++.NET and I've got a listbox with some items in it via Properties->Collection. They're strings and I want the user to choose one of the strings in the list box and then pass that string (a number from 1 to 12) to a function that will fill another list box with data from a database according to which number was chosen. Can I just use regular atoi to convert the string or do i need to use something like

    listBox1->Text...conversion... ???

    Thanks for your help.

    Swaine777

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    atoi only works with C-style strings. If your string is a C-style string or if it has a conversion to a C-style string (such as std::string's c_str member function) you can use atoi. Otherwise you cannot. Unfortunately, in C++ "string" can mean several mutually exclusive types, so you'll have to be more specific as to how you declare this string.
    My best code is written with the delete key.

  3. #3
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    If you're using the .NET CLR you can use the Int32::Parse() method...

    int MyInt = Int32::Parse("154"); // MyInt = 154

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    My guess is he is using the string class that is defined by Microsofts library, probably System::String. Only a guess though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. migrate from .Net 2.0 to .Net 3.0
    By George2 in forum C# Programming
    Replies: 3
    Last Post: 07-25-2007, 04:07 AM
  2. Some .NET Distribution Stats
    By nickname_changed in forum C# Programming
    Replies: 2
    Last Post: 05-14-2005, 03:41 AM
  3. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM
  4. .net
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 02-15-2002, 12:15 AM
  5. Visual J#
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 02:41 PM

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