Cin Maximum characters.

This is a discussion on Cin Maximum characters. within the C++ Programming forums, part of the General Programming Boards category; I was wondering if theres a way to have a maximum ammount of characters when using cin, also is there ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    69

    Cin Maximum characters.

    I was wondering if theres a way to have a maximum ammount of characters when using cin, also is there a way to change the text color, and the background color of the command prompt window?

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    I tried to find a definite answer for this, but it depends on what type of an identifier you're reading into. You could do some tests to check how many digits you can read into an int, or how many characters you could read into a string, for example.

    if your identifier is an char, well then you could read only a single character.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Check MSDN.com. With <windows.h> included, you can change text colors and such, I believe.

    And the way to have a max amount of characters is cin.getline(string,MAX,term_char)

    Code:
    cin.getline(myString,100, '\n');

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    And once again, the FAQ comes to the rescue!

    As to the first question, I am not sure, but my guess is that the answer lies somewhere in numeric_limits.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Quote Originally Posted by Zach L.
    And once again, the FAQ comes to the rescue!

    As to the first question, I am not sure, but my guess is that the answer lies somewhere in numeric_limits.
    I did try using the textcolor function, but I get errors when I compile. Im using Microsoft Visual C++.

    Dont see whats wrong here.

    Code:
    #include <iostream>
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    using std::cout;
    using std::cin;
    char command;
    int ch;
    // Inpute Function. checks all input.
    void inpute()
    { 
    textcolor ( MAGENTA );
    cprintf ( ">> \n" );
    cprintf ( ">> "  );
    }

    I get these errors

    Code:
    c:\documents and settings\blade-new\my documents\visual studio projects\admin\funcs.h(12) : error C2065: 'textcolor' : undeclared identifier
    c:\documents and settings\blade-new\my documents\visual studio projects\admin\funcs.h(12) : error C2065: 'MAGENTA' : undeclared identifier
    
    Error executing cl.exe.
    
    ADMIN.exe - 2 error(s), 0 warning(s)

  6. #6
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    I see, you clicked on the link, but have not read it thoroughly enough...look for the windows platform color change

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  7. #7
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Oh, yes I see, but theres only 3 colors . Thanks though

  8. #8
    fuh
    fuh is offline
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    Quote Originally Posted by bladerunner627
    Oh, yes I see, but theres only 3 colors .
    You can mix them.
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  9. #9
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Quote Originally Posted by fuh
    You can mix them.
    How exactly?

  10. #10
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Quote Originally Posted by bladerunner627
    How exactly?
    Use the bitwise-or operator.
    Code:
    SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_BLUE );
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Removing Specific Characters from Strings
    By gfmartin05 in forum C++ Programming
    Replies: 4
    Last Post: 02-09-2009, 08:53 AM
  2. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  3. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  4. Function using cin
    By Sub in forum C++ Programming
    Replies: 6
    Last Post: 01-08-2002, 03:29 PM
  5. limit the characters using gets function
    By yukon in forum C Programming
    Replies: 6
    Last Post: 10-08-2001, 02:15 PM

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