Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7163797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:57:47+00:00 2026-05-28T13:57:47+00:00

In C++ I have only seen this done by converting the string object into

  • 0

In C++ I have only seen this done by converting the string object into an array of characters. The tutorials with an array are a bit hard for me to understand. But I want to do the conversion without the array.

I do have an idea how to do it: the string is “1234”. After that I convert this text to an integer this way:

if (symol4 == "4") int_var += 4 * 1;
if (symol3 == "3") int_var += 3 * 10;
if (symol3 == "2") int_var += 2 * 100;
if (symol3 == "1") int_var += 1 * 1000; //Don't worry, I'm familiar with cycles, this code is only for explaining my algorithm

I hope you can understand the idea.

But I don’t know if this is the best way. I don’t know if there is a library that has a function that allows me to do that (I won’t be surprised if there is one).

I don’t know if not using a char array is a good idea. But that’s a different question that I’m going to ask later.

What’s the best way to convert a string to an integer, double, etc WITHOUT using an array of characters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:57:48+00:00Added an answer on May 28, 2026 at 1:57 pm

    boost::lexical_cast to the rescue: int result = boost::lexical_cast<int>(input)

    If you don’t want to rely on boost, you can use a stringstream, something like:

    std::stringstream ss;
    int result;
    ss << input;
    ss >> result;
    

    but that’s rather roundabout imo

    And no don’t use atoi – that function was flawed even back in C and it hasn’t gotten better with time. It returns 0 when an error happened while parsing – which has the obvious problem how you distinguish an error from parsing the string "0".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The only way I've seen this done in the tutorials I've looked at, they
Okay i've seen this done somewhere before where you have a function that takes
I have seen XML Schema element with attributes containing only text but I have
I have only recently started working with the MVC approach, so I suppose this
I have only this in my mxml source code: <?xml version=1.0 encoding=utf-8?> <mx:Canvas xmlns:mx=http://www.adobe.com/2006/mxml
I've seen this done in a lot of sites recently, but can't seem to
I know I've seen this done a lot in places, but I need something
AM a newbie in php, i have seen some web applications that have only
Now I have seen this question in another forum but it didn't had an
Note: I have seen this and tried to take as much from it as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.