#include &lt;iostream&gt; using namespace std; int main () {     string a;     cin &gt;&gt; a;     int b=10;     cout &lt;&lt; a+b;     return 0; }   I have a problem with the code above. I know it's wrong, but it shows my point.   I'm wondering if I get a number as a string, how can I have it as an integer? For example, I give 12 to the program after running. So a will be "12". Now I want the summation of 12 and the variable b. What should I do? How can I extract 12 as an integer from my string?
15391
What's the C++ way of parsing a string (given as char *) into an int? Robust and clear error handling is a plus (instead of ).
4408
I just noticed that you can not use standard math operators on an enum such as ++ or +=  So what is the best way to iterate through all of the values in a C++ enum?
610
I've always wondered how to write the "A ? B : C" syntax in a C++ compatible language.  I think it works something like: (Pseudo code)  If A &gt; B    C = A Else    C = B   Will any veteran C++ programmer please help me out?
59699
Here is the code.  \documentclass{article} \begin{document} \directlua{tex.sprint(tostring(math.sin(math.pi)))} \\ \directlua{tex.sprint(tostring(math.tan(math.pi/2)))} \end{document}   I am expecting the answers as 0 and error . The code above gives some very small and big number. Can I get the expected answers by some modifications in code?
46742
Is there a library or a class/function that I can use to convert an integer to it's verbal representation?  Example input:     4,567,788`   Example output:     Four million, Five hundred sixty-seven thousand, seven hundred eighty-eight
11107
Is there a function the .NET framework that can evaluate a numeric expression contained in a string and return the result? F.e.:  string mystring = "3*(2+4)"; int result = EvaluateExpression(mystring); Console.Writeln(result); // Outputs 18   Is there a standard framework function that you can replace my EvaluateExpression method with?
14414
I am trying to convert an integer number in C into an array containing each of that number's digits  i.e.  if I have   int number = 5400   how can I get to   int numberArray[4]   where   numberArray[0] = 0; numberArray[1] = 0; numberArray[2] = 4; numberArray[3] = 5;   Any suggestions gratefully received.
100452
CString is quite handy, while std::string is more compatible with STL container. I am using hash_map. However, hash_map does not support CStrings as keys, so I want to convert the CString into a std::string. Writing a CString hash function seems to take a lot of time. CString -----&gt; std::string  How can I do this? std::string -----&gt; CString:  inline CString toCString(std::string const&amp; str) {     return CString(str.c_str());  }  Am I right?  EDIT: Here are more questions: How can I convert from wstring to CString and vice versa? // wstring -&gt; CString std::wstring src; CString result(src.c_str());  // CString -&gt; wstring CString src; std::wstring des(src.GetString());  Is there any problem with this? Additionally, how can I convert from std::wstring to std::string and vice versa?
22068
Why is Array.Length an int, and not a uint. This bothers me (just a bit) because a length value can never be negative.   This also forced me to use an int for a length-property on my own class, because when you  specify an int-value, this needs to be cast explicitly...  So the ultimate question is: is there any use for an unsigned int (uint)? Even Microsoft seems not to use them.
8128
What is the best possible way to check if a string can be represented as a number in Python?   The function I currently have right now is:  def is_number(s):     try:         float(s)         return True     except ValueError:         return False   Which, not only is ugly and slow, seems clunky. However I haven't found a better method because calling float in the main function is even worse.
5691
Is there a better way of getting this result? This function fails if num has more digits than digits, and I feel like it should be in the library somewhere (like Integer.toString(x,"%3d") or something)  static String intToString(int num, int digits) {     StringBuffer s = new StringBuffer(digits);     int zeroes = digits - (int) (Math.log(num) / Math.log(10)) - 1;      for (int i = 0; i &lt; zeroes; i++) {         s.append(0);     }     return s.append(num).toString(); }
47079
With the listings package, I would like to color the integers out of strings and comments and out of keywords too. The question for coloring numbers     . Some answer handle the numbers occurring within comments, strings or barewords, but no solution given work when a keyword contain a number. Which is annoying because C and C++ have a lot of types with a number in them, like uint32_t.  Here is a small example.  \documentclass{standalone} \usepackage{xcolor} \usepackage{listings}  \definecolor{darkgreen}{rgb}{0.18,0.54,0.34} \definecolor{maroon}{rgb}{0.64,0.16,0.16} \definecolor{darkpink}{rgb}{0.75,0.25,0.5}  \lstdefinestyle{myc++}{     language=[ISO]C++,     keywordstyle=\color{darkgreen}\bfseries,     commentstyle=\color{blue}\textit,     stringstyle=\color{darkpink}\ttfamily, %     literate=*     {0}{{{\textcolor{red}0}}}1     {1}{{{\textcolor{red}1}}}1     {2}{{{\textcolor{red}2}}}1     {3}{{{\textcolor{red}3}}}1     {4}{{{\textcolor{red}4}}}1     {5}{{{\textcolor{red}5}}}1     {6}{{{\textcolor{red}6}}}1     {7}{{{\textcolor{red}7}}}1     {8}{{{\textcolor{red}8}}}1     {9}{{{\textcolor{red}9}}}1,     escapeinside={|}{|}, %     morekeywords={int32_t} }  \begin{document}  \begin{lstlisting}[style=myc++] // In comment: 42 int32_t in_keyword = 80085; char *in_identifier|2| = "And in string 1337\n"; \end{lstlisting}  \end{document}   And the result:    The star for literate avoid to coloring the digits inside comments or strings. The escapeinside avoid coloring the digits inside a bareword when specifically marked. But I have yet to find how to color int32_t as a keyword.
35095
Is there a way to convert a number to a string (Apex code, formula field ..)  For example: 5200 > cinq milles deux cents
80591
Although I'm doubtful, I'm curious as to whether it's possible to extract primitive-type template parameters from an existing type, perhaps using RTTI.  For example:  typedef std::bitset&lt;16&gt; WordSet;   Would it be possible to extract the number 16 in the above code without hard-coding it elsewhere? Compiler specific implementations are welcome, though I'm particularly interested in g++.
244
How does the comma operator work in C++?  For instance, if I do:  a = b, c;     Does a end up equaling b or c?   (Yes, I know this is easy to test - just documenting on here for someone to find the answer quickly.)  Update:  This question has exposed a nuance when using the comma operator.  Just to document this:  a = b, c;    // a is set to the value of b!  a = (b, c);  // a is set to the value of c!   This question was actually inspired by a typo in code.  What was intended to be  a = b; c = d;   Turned into  a = b,    //  &lt;-  Note comma typo! c = d;
12536
I was working with a new C++ developer a while back when he asked the question: "Why can't variable names start with numbers?"  I couldn't come up with an answer except that some numbers can have text in them (123456L, 123456U) and that wouldn't be possible if the compilers were thinking everything with some amount of alpha characters was a variable name.  Was that the right answer?  Are there any more reasons?  string 2BeOrNot2Be = "that is the question"; // Why won't this compile?
50427
We all know that you can overload a function according to the parameters:  int mul(int i, int j) { return i*j; } std::string mul(char c, int n) { return std::string(n, c); }    Can you overload a function according to the return value? Define a function that returns different things according to how the return value is used:  int n = mul(6, 3); // n = 18 std::string s = mul(6, 3); // s = "666" // Note that both invocations take the exact same parameters (same types)   You can assume the first parameter is between 0-9, no need to verify the input or have any error handling.