question related to keypad

This is a discussion on question related to keypad within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <sstream> //ostringstream, str() using namespace std; int main() { ostringstream out; int n = 2; out<<n; ...

  1. #16
    Registered User
    Join Date
    Dec 2005
    Posts
    11
    Code:
    #include <iostream>
    #include <sstream>  //ostringstream, str()
    using namespace std;
    
    
    int main() {
       
    	ostringstream out;
    
    	int n = 2;
    	out<<n;
    
    	n = 5;
    	out<<n;
    
    	n = 7;
    	out<<n;
    
    	string str = out.str();
    
    	cout<<str<<endl;
    
    	return 0;
    }
    to all the users, please help me... instead of using stringstream, is there another other methods?
    my complier do not allow the using of namespace std

  2. #17
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    if you can't use using namespace std then can you use std:: in the appropriate places?

  3. #18
    Registered User
    Join Date
    Dec 2005
    Posts
    11
    sorry... i cant use std:: in my complier too... is there another other methods to input in data beside using of stringstream?

  4. #19
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    I think a stringstream is probably overkill here. It's sounds like some sort of embedded platform so a stream might use too much memory/processor.

    just do something simple like
    Code:
    int value = 0;
    int keypadVal = GetKeyPadValue(); // get number from keypad
    do
    {
        // decimal shift!
        value += (10 * value) + keypadVal;
        keypadVal = GetKeyPadValue(); // get number from keypad
    }
    while (keypadVal != NO_MORE_KEYS); // or some other signal
    that's straight off the top of my head, so prob contains both syntax and logic errors but you get the idea
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  5. #20
    Registered User
    Join Date
    Dec 2005
    Posts
    11
    thanks alot...

    i am a newbie to programming...

    can someone please give me some pointers on how to convert char to int... i cannot find anything on the search engines... thanks.

  6. #21
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by lovemagix
    thanks alot...

    i am a newbie to programming...

    can someone please give me some pointers on how to convert char to int... i cannot find anything on the search engines... thanks.
    you can't be looking very hard... that must be one of the most commonly asked C/C++ questions!

    but to give you a headstart

    in C:
    atoi
    sscanf

    in C++:
    std::stringstream
    or even cooler
    boost::lexical_cast

    I still don't think you need to convert to char in the first place though
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  7. #22
    Registered User
    Join Date
    Dec 2005
    Posts
    11
    sorry.... i looking hard because... all the source codes that deal with hexa conversion uses stringstream... for my complier, i cannot use stringstream... is there another other ways.. please

  8. #23
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,688
    > my complier do not allow the using of namespace std
    Get one that does, or get left behind.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to dynamic memory allocation
    By spiit231 in forum C Programming
    Replies: 2
    Last Post: 03-11-2008, 12:25 AM
  2. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  3. Yacc question related to %type
    By g_p in forum Tech Board
    Replies: 0
    Last Post: 05-31-2007, 09:55 AM
  4. Question related to getpid and getppid
    By g_p in forum C Programming
    Replies: 4
    Last Post: 12-18-2006, 10:35 AM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM

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