User input question

Hi,

I am wondering how could I save user input to a variable, which size can be dynamicly changed. So, an char * or whatever, that wouldn't have defined length (char * string;) but would be as long as the string of characters entred by user.

>>Enter a string:
<<Štring

(string={'Š', 't', 'r', 'i', 'n', 'g'};)


*please note that I gave exceptions, which I used but did not work.

PS: Where could I get some info on bitmaps and how to save them w/out special libraries....bmp should be the simplest format to save but I cant manage even that
1) You mixing up two entirely different questions in one thread.
2) How about std::string?
3) What do you want to save bitmaps for?
Last edited on
Read a string:
1
2
3
4
5
6
#include <iostream>
int main() {
    std::string str;
    std::getline(std::cin, str);
    std::cout << str << std::endl;
}


Information about how to save BMP:
Google for "bmp specification", and any of the top results should give you all you need.
Thanks, works like a charm. About bitmaps...they were on my mind atm, and why not asking the question which you can just ignore, if it bugs you.

Magnus, I want to save bitmaps for futhure viewing, so they would be writen on hard disk, not just ram, dont know why else should I save somthing...
Nay, it's just that it makes no sense in the context of this thread and your code example. Where do you get a bitmap from? And why should a bitmap image be the simplest encoding to save in? You never mentioned that...
I am looking for a image format to save images in, that would be easy to write, for I am learning. My program would make the bitmap itself, or any other format of image that is easy enough and than just write it with an output filestream.
So you want to build a drawing program? Then why reinvent the wheel? Use an API that suites your needs.
:) Of curse I can always do that, I just wanted to do it myself from start, btw I managed to create a program that creates a 24bit bmp image and saves it. Loved it:P

Thanks for your help and time
Topic archived. No new replies allowed.