Q:

converting from strings to ints

I would like to know what is the easiest way to convert an int to C++ style string and from C++ style string to int.
edit
Thank you  very much. When converting form string to int what happens if I pass a char string ? (ex: "abce"). 
Thanks & Regards,
Mousey

A:

Probably the easiest is to use operator<< and operator>> with a stringstream (you can initialize a stringstream from a string, and use the stream's .str() member to retrieve a string after writing to it.
Boost has a lexical_cast that makes this particularly easy (though hardly a paragon of efficiency). Normal use would be something like int x = lexical_cast<int>(your_string);

A:

This is to convert string to number.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream>

int convert_string_to_number(const std::string& st)
{
    std::istringstream stringinfo(st);
    int num = 0;
    stringinfo >> num;
    return num;
}

int main()
{
    int  number = 0;

    std::string number_as_string("425");
    number = convert_string_to_number(number_as_string);

    std::cout << "The number is " << number << std::endl;
    std::cout << "Number of digits are " << number_as_string.length() << std::endl;
}

Like wise, the following is to convert number to string.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream>

std::string convert_number_to_string(const int& number_to_convert)
{
    std::ostringstream os;
    os << number_to_convert;
    return (os.str());
}

int main()
{
    int number = 425;

    std::string stringafterconversion;
    stringafterconversion = convert_number_to_string(number);

    std::cout << "After conversion " << stringafterconversion << std::endl;
    std::cout << "Number of digits are " << stringafterconversion.length() << std::endl;
}

