LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-30-2006, 11:00 AM   #1
adilturbo
Member
 
Registered: Jun 2006
Location: morocco
Posts: 195

Rep: Reputation: 30
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)
 
Old 06-30-2006, 11:12 AM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
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.
 
Old 07-02-2006, 03:31 PM   #3
mhcox
Member
 
Registered: Aug 2005
Location: Albuquerque, NM
Distribution: Fedora
Posts: 30

Rep: Reputation: 15
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
 
Old 07-03-2006, 11:22 AM   #4
adilturbo
Member
 
Registered: Jun 2006
Location: morocco
Posts: 195

Original Poster
Rep: Reputation: 30
thank you all
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cin/cout part of c or just c++ true_atlantis Programming 4 02-25-2006 06:54 PM
How to cin >> string? kornerr Programming 2 11-01-2005 03:58 AM
cin.ignore Xiangbuilder Programming 4 10-08-2003 07:57 PM
g++ and cin.getline() codeviking Programming 8 07-03-2003 07:42 AM
cin.getline adam_boz Programming 6 10-02-2002 08:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration