stringstream流格式化符,把int转化为string,string又可以转为C语言风格的字符串

#include
#include
#include
using namespace std;

int main( void )
{
    int i = 12345;
	stringstream s;//流格式化符,把int转化为string

	s << i;
	string str = s.str(); //等到string类型的字符串 

	cout << str << endl;
	
	const size_t BUF_SIZE = 8;
	char buf[BUF_SIZE];
	strcpy( buf, str.c_str( ));
	cout << buf << endl; //等到C语言风格(C-style)的字符串 


    system( "PAUSE" );
    return EXIT_SUCCESS;
}

/*-----------
12345
12345
请按任意键继续. . .
-----------------------*/

你可能感兴趣的:(C++)