How to use istringstream() in C++

2 Answers

0 votes
#include <iostream>
#include <sstream>

using std::cout;
using std::endl;

int main()
{
	int n;

	std::istringstream("AF") >> std::hex >> n;

	cout << n << endl;

	return 0;
}

/*
run:

175

*/

 



answered Apr 5, 2018 by avibootz
0 votes
#include <iostream>
#include <sstream>

using std::cout;
using std::endl;

int main()
{
	std::ostringstream os;

	os << "dec: " << 32 << " hex: " << std::hex << 32 << endl;

	cout << os.str() << endl;

	return 0;
}

/*
run:

dec: 32 hex: 20

*/

 



answered Apr 5, 2018 by avibootz

Related questions

1 answer 118 views
118 views asked Jan 24, 2021 by avibootz
...