c++ create a string during run time?

Mar 15, 2012 at 6:33am
I need a way to create a string during runtime so that the user may fill it with any size hexadecimal using cin and then later I must convert it to decimal.

So I need something that can be created during runtime so that its size isn't set and I need it to be something that I can then easily get the length of it so I know how many elements are in the string or array.

Its been a long day, anyone that could help me with this starter step would be awesome. I've already planned out the majority of the program and am hung up on this stupid problem and feel like an idiot, lol. Thanks!
Mar 15, 2012 at 6:43am
Use std::string.
It does everything you need it to do. (and more)

http://www.cplusplus.com/reference/string/string/
Mar 15, 2012 at 6:52am
I'll look into it first thing in the morning! Does it allow the string to be created from cin without a set size? If you have time to show me a quick example similar to what I'm looking to do (as far as creating something from cin input) if not I will research when I get back to it tomorrow. Thanks again for the reply.
Mar 15, 2012 at 7:03am
I don't exactly know what u're trying to do, but I see you want to work with strings and cin?
Here's a quick example:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string firstName, lastName;
	cout << "What's ur name? (first and last)\n";
	cin >> firstName >> lastName;
	cout << "Hello\t" << firstName << ' ' <<lastName;
	cin.get();
	return 0;
}
Topic archived. No new replies allowed.