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?
Printable View
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?
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.
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');
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++.Quote:
Originally Posted by Zach L.
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)
I see, you clicked on the link, but have not read it thoroughly enough...look for the windows platform color change
Oh, yes I see, but theres only 3 colors :(. Thanks though
You can mix them.Quote:
Originally Posted by bladerunner627
How exactly?Quote:
Originally Posted by fuh
Use the bitwise-or operator.Quote:
Originally Posted by bladerunner627
Code:SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_BLUE );