none
convert integer to string and string to integer RRS feed

  • Question

  • i want to covert string to integer then i want to change integer value of char. After i want to convert new form to string. how can i do ?

    ex:

    string = e   integer = 101
    new value =1
    01*2  new string = -

    Saturday, March 31, 2007 5:41 PM

Answers

  • Hi,
    check this example:

    #include <string>
    using namespace std;

    int main()
    {
      string s = "a";
      int i = s[0]; // i contains 97
      s = i + 1; // s now contains b
      return 0;
    }


    Saturday, March 31, 2007 11:05 PM

All replies

  • Hi,
    check this example:

    #include <string>
    using namespace std;

    int main()
    {
      string s = "a";
      int i = s[0]; // i contains 97
      s = i + 1; // s now contains b
      return 0;
    }


    Saturday, March 31, 2007 11:05 PM
  • See the example.
    There's nothing more than the previous reply you got for this question. You don't need to put the value in a temporary variable and re-assign. You can modify each element of string at valid index with the help of operator[]

    Code Snippet

    string str = "e";
    str[0] *= 2;
    cout<< str;

    Monday, April 2, 2007 2:38 PM