Search 5,000,000+ questions and answers.

Frequently Asked Questions

Q. How do I convert from string to int?

C++ FAQs - General
The simplest way is to use the function int std::atoi(const char*) declared in cstdlib. For example, std::atoi("31337") returns 31337. Alternatively, you can use std::strtol() or std::strtoul(). These functions provide more functionality such as the ability to convert hexadecimal or octal number strings, and are also declared in cstdlib.
Related Questions

Q. How do I convert from int to string?

C++ FAQs - General
Converting from int to string is a little more complicated than converting a string to int. There are no standard C++ functions for this, but there is a way to do it using standard stringstreams. The class stringstream is declared in header sstream and is used like this:
Related Questions

How can I convert from string to int ?

C++ corner
You want to make a function that converts from a type to another. Like from std::string to int, or the other way around. This can be done using std::stringstream and insertion / extraction operators. Just as above, templates will prove of great help: Its usage is not as straightforward as the above explained max template. Normally, you would want to call it like "int value = lexical_cast( myStdString );". There is, however, a problem.
Related Questions

FAQ - CPP
The simplest way is to use the function int std::atoi(const char*) declared in cstdlib. For example, std::atoi("31337") returns 31337. Alternatively, you can use std::strtol() or std::strtoul(). These functions provide more functionality such as the ability to convert hexadecimal or octal number strings, and are also declared in cstdlib.
Related Questions

How do I convert from int to string?

FAQ - CPP
Converting from int to string is a little more complicated than converting a string to int. There are no standard C++ functions for this, but there is a way to do it using standard stringstreams. The class stringstream is declared in header sstream and is used like this: std::stringstream ss; std::string str; ss << 31337; ss >> str;
Related Questions

How do I convert a string to an int etc?

FAQ for the microsoft.public.languages.csharp newsgroup
In general, when you want to convert from one type to another, the first class to look at is System.Convert. It has a load of static methods which are likely to help you. If you're converting from a String, you could also check whether the type that you want to convert to has a Parse method or something similar - for instance, I usually use DateTime.ParseExact to convert from a String to a DateTime.
Related Questions

Sect. 18) How do I convert a String to an int?

Java Programmer's FAQ - Part D
There are several ways. The most straightforward is: String myString = numString.trim(); int i = Integer.parseInt(myString); long l = Long.parseLong(myString) or String myString = numString.trim(); i = Integer.parseInt(myString,myIntRadix); Note 1: There is a gotcha with parseInt - it will throw a NumberFormatException for String values in the range "80000000" to "ffffffff". You might expect it to interpret them as negative, but it does not. The values have to be "-80000000" .
Related Questions

Sect. 18) How do I convert an int to a string?

Java Programmer's FAQ - Part D
Try any of these: String s = String.valueOf(i); or String s = Integer.toString(i); or String s = Integer.toString(i, radix); or // briefer but may result in extra object allocation. String s = "" + i; Note: There are similar classes for Double, Float, Long, etc.
Related Questions

How to convert an int to a char array or C++ string?

Tech Talk about C++ and C Issues / Comeau C++ and C FAQ
How to add a float (or "any" type really) to the end of a C++ string? Unlike routines like atoi mentioned in the previous question, there is no direct routine such as itoa available. However, similar to the string I/O routines in the previous question, one can do this: #include <stdio.h> // cstdio in C++ // ..
Related Questions

How do I convert a string to a double or int? What plays the role of atof and atoi in C#?

Windows Forms FAQ - Windows Forms from MFC
You use static members of the Convert class found in the System namespace to handle conversions in the .NET framework.
Related Questions

How can I convert an INT into CHAR*/STRING or vice versa?

Beginner FAQ - GPWiki
This is something you do a lot in programming and pretty much every language makes it easy to convert between types. You may have already printed integers to the console with COUT or PRINTF, which of course needs to be converted to a string first. Converting numbers to strings is done in a similar way. Boost is a C++ library that can help you with problems like these and many others.
Related Questions

How do I convert a string to a number?

Updating the For Beginners forum FAQ - GameDev.Net Discussio...
I am including the header file <string>, and I am using the string class, but the code doesn't compile? (namespace resolution, having the std:: topics) How do I use unique() with vectors? (answered only once, but still a good question to have due to people not knowing that it's possible to do)
Related Questions

How should I round a double up to an int? Q: How do I get the name of the operating system?

Code Style: Java programming frequently asked questions (FAQ...
To get the operating system name in Java use the static System.getProperty("os.name") method, which returns a string. Other operating system property keys are "os.arch" for the hardware architecture and "os.version" for the version number. A recursive method is one whose method body includes a call to itself, so that it is called repeatedly until an expected condition is met or it cannot continue the recursion any longer.
Related Questions

Q. How do I convert a char to its ASCII value, or vice versa?

C++ FAQs - General
To convert a char to its ASCII value, simply cast it to an integer. For example, the expression static_cast<unsigned int>('A') will evaluate to 65. To convert an ASCII value to its corresponding character is similarly simple. The expression static_cast<char>(65) will evaluate to 'A'.
Related Questions

How to convert the datetime into a string for use in the SQL ' statement?

Megasolutions.net :: Asp.Net Frequently Asked Questions - FA...
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Private Sub ddlCulture_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlCulture.SelectedIndexChanged
Related Questions

How do I convert an integer to a string representation?

CSC 209 Summer 2006
Well, printf does it for output, so look at its related function named sprintf that "prints formated output to a string."
Related Questions

How can I convert an integer or a float to a string?

Frequently Asked Questions
It's easy. Use sprintf. For example: char string1[50]; char string2[50]; short int var1; float var2; ... sprintf (string1, "%d", var1); sprintf (string2, "%f", var2);
Related Questions

How do I convert a std::string to a number?

Miscellaneous technical issues, C++ FAQ Lite
There are two easy ways to do this: you can use the <cstdio> facilities or the <iostream> library. In general, you should prefer the <iostream> library.
Related Questions

How do I convert a string into an internet address?

Programming UNIX Sockets in C - Frequently Asked Questions: ...
If you are reading a host's address from the command line, you may not know if you have an aaa.bbb.ccc.ddd style address, or a host.domain.com style address. What I do with these, is first try to use it as a aaa.bbb.ccc.ddd type address, and if that fails, then do a name lookup on it. Here is an example: Converts ascii text to in_addr struct. NULL is returned if the address can not be found.
Related Questions

Multi-threaded design questions Q: Do I need to use synchronized on setValue(int)?

Code Style: Java threads frequently asked questions (FAQ)
It depends whether the method affects method local variables, class static or instance variables. If only method local variables are changed, the value is said to be confined by the method and is not prone to threading issues.
Related Questions

Do I need to use synchronized on setValue(int)? Q: How do I create a Runnable with inheritance?

Code Style: Java threads frequently asked questions (FAQ)
To introduce a Runnable type to an existing class hierarchy, you need to create a sub-class that declares that it implements the Runnable interface, and provide a run method to fulfil the interface. This combination of interface and inheritance means that runnable implementations can be very minor extensions of existing classes, as in the example below..
Related Questions

How do I read a String/int/boolean/etc from the keyboard?

Java Programmer's FAQ
The easiest way is to pick up the source for the 100% pure Java class EasyIn from http://www.afu.com/ (same place as this FAQ) Compile it with your code and use it like this: EasyIn easy = new EasyIn(); int i = easy.readInt(); // gets an int from System.in boolean b = easy.readBoolean(); // gets a boolean from System.in double d = easy.readDouble(); // gets a double from System.in ... etc.
Related Questions

How can I show an int as a binary number - a string of 1s and 0s?

FAQ for the microsoft.public.languages.csharp newsgroup
The Convert class has an overload of the static ToString() method that takes two ints and returns a string populated with the number in the specified base. For instance, calling Convert.ToString(128, 2) will return "10000000".
Related Questions

Can QEngine script support string/int variable?

AdventNet QEngine - Frequently Asked Questions
Yes, QEngine supports string/int variables usage in the script. This will help you to use the business logics of your application to validate the results shown in your pages. For e.g., you can define a variable like below variableA=25 variableB=”Use this string” You can also cast a string variable to int for using it in a loop structure or somewhere else like below. variableA=”25” // int value stored as a string variable.
Related Questions

Can QEngine support to manipulate any string / int data inside the script?

AdventNet QEngine - Frequently Asked Questions
Yes, you can manipulate any string/int data inside the script. You can use + - * / for int value manipulations. For string manipulation QEngine provides you many functions like Java
Related Questions

Q 12.2: How can I search for, or filter, packets that have a particular string anywhere in them?

Wireshark: Frequently Asked Questions
If you want to do this when capturing, you can't. That's a feature that would be hard to implement in capture filters without changes to the capture filter code, which, on many platforms, is in the OS kernel and, on other platforms, is in the libpcap library. In releases prior to 0.9.14, you also can't search for, or filter, packets containing a particular string even after you've captured them. In 0.9.
Related Questions

How to convert a string to a number using JavaScript?

AKAAS :: JavaScript Interview Questions and Answers | JavaSc...
You can use the parseInt() and parseFloat() methods. Notice that extra letters following a valid number are ignored, which is kinda wierd but convenient at times.
Related Questions

Got A Question? Ask Our Community!


More Questions >>

© Copyright 2007-2008 QueryCAT
About • Webmasters • Contact