LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++::std::cin (https://www.linuxquestions.org/questions/programming-9/c-std-cin-459775/)

adilturbo 06-30-2006 11:00 AM

C++::std::cin
 
hi all,
how can i specify to cin number of character to read from input?
eg:
input: Dec90
so i want to stock Dec in a string variable, and 90 in int variable.

i think in C is something like:

Code:

scanf("%3s%2d",&STRING,&INTEGER)

tuxdev 06-30-2006 11:12 AM

Streams are designed to tokenize input. Either make sure the input read in is whitespace separated or separated by some other special char, or just use the C function and forget about streams.

mhcox 07-02-2006 03:31 PM

Quote:

Originally Posted by tuxdev
Streams are designed to tokenize input. Either make sure the input read in is whitespace separated or separated by some other special char, or just use the C function and forget about streams.

You can also use a combination of formatted (tokenized) input and unformated input:

char date[4]; // 4 for terminating nul that get() adds.
int year;
cin.get(date, 3) >> year;

Mike

adilturbo 07-03-2006 11:22 AM

thank you all


All times are GMT -5. The time now is 01:51 AM.