Manipulating the input from the user.

This is a discussion on Manipulating the input from the user. within the C++ Programming forums, part of the General Programming Boards category; hello, i am doing an assignment and in it, I want to ask the user for two numbers( a row ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    21

    Manipulating the input from the user.

    hello,
    i am doing an assignment and in it, I want to ask the user for two numbers( a row and a column) but it should be in the format of x:y
    where x is the row and y is the column.
    My question, how can i take this input and put it in two separate variables to use?
    I thought of using a string for the input variable but i don't know how to change that to a string and get the two variables separate.

    thanks in advance.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,427
    Input a string, then separate them into strings and convert them into integers.
    I assume you know how to input a string.
    To separate them, use find() and substr() to find the ":" and to extract the parts, respectively. Or you could just cheat and use boost::split. There are some examples on the web.
    To convert the strings into integers, use stringstreams. Or you could just cheat and use boost::lexical_cast.

    Good luck.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i need help with getting input from the user.
    By nyekknyakk in forum C Programming
    Replies: 7
    Last Post: 08-17-2010, 10:22 PM
  2. Manipulating Input
    By Sridar in forum C++ Programming
    Replies: 3
    Last Post: 02-13-2005, 10:24 AM
  3. Manipulating input streams.....
    By theBigBopper in forum C++ Programming
    Replies: 2
    Last Post: 10-27-2002, 03:25 PM
  4. user input
    By hen in forum C Programming
    Replies: 1
    Last Post: 08-02-2002, 11:37 AM
  5. User input?
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 11-23-2001, 06:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21