Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

seperating input from cin

Posted on 2000-03-27
1
Medium Priority
?
175 Views
Last Modified: 2010-04-02
I need to be able to seperate values from cin to 2 separate variables.  For Example:

1430 needs to be put into two variables:

variable1 = 14, variable 2 = 30

Additionally, input could be formatted as:

14:30
and then,
variable1 = 14, variable2 = 30
0
Comment
Question by:psisung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
nietod earned 150 total points
ID: 2661483
you will have to read the value in as an ASCII string and then convert the string to numbers, like

char Lin[80]
char NumStr[3];
int variable1 = 0;
int variable2 = 0;

cin.getline(Lin,80);
strncpy(NumStr,Lin,2);
NumStr[2] = 0;
variable1 = atoi(NumStr);

if (isdigit(Lin[2]))
  strncpy(NumStr,Lin+2,2);
else
  strncpy(NumStr,Lin+3,2);
variable2 = atoi(NumStr);

You may have to change this depending ont he exact rules you decide apon  for parsing the two numbers.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question