Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 14th, 2005, 11:46 AM
Registered User
 
Join Date: Mar 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems with cin

Hello,

currently i'm writing a program for my exams, and i happened upon a problem with cin. My program requies a login inputted by the user which is 20 chars long. I have written a function that cuts 20 first chars if user inputted more chars (to avoid buffer overflow), but i was wondering if it's possible to overload cin in a way that if user inserted 20 chars then no more is accepted and user is to correct inputted login or press enter.

Thanks in advance

Reply With Quote
  #2 (permalink)  
Old March 17th, 2005, 10:41 AM
Authorized User
 
Join Date: Mar 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

//excuse my bad english in advance
//because I don't use it all the time
****************************
Object oriented programming
****************************
INPUT AND OUTPUT IN C++

INPUT
#include <iostream>
int main(){
int n; double d;
std::cin >> n >> d;
   return 0;
}

OUTPUT
#include <iostream>
int main(){
int n = 10;
std::cout << n << '*' << n << " je " << n*n;
   return 0;
}

MANIPULATORS:
ends (end of string)
endl (end of line)
flush (flushing the buffer)
setprecision (precision of real numbers)
setw (print width)
setbase (base of whole numbers 8, 10 or 16)
setfill (fill sign)
setiosflags (sets certain formats)(see: ios flags)
resetiosflags (resets given formats)(see: ios flags)

IOS FLAGS:
boolalpha (prints bool values as a string,else as number)
dec (decimal format for whole numbers)
fixed (floating point format for real numbers)
hex (hexadecimal fotmat for whole numbers)
internal (empty spaces between sign and number- or base mark)
left (left alignment)
oct (octal format for whole numbers)
right (right alignment)
scientific(exponential form for real numbers)
showbase (prefiks for base of a whole numbers)
showpoint (decimal point)
showpos (plus sign)
skipws (skipping whitespaces - spaces, tabs, ...)
unitbuf (buffer emptying after every input)
uppercase (upper letters A-F in heksadecimal view)

example:
#include <iostream>
#include <iomanip>
int main(){
double d = 123.456789;
std::cout << std::setiosflags(std::ios::scientific | std::ios::left);
std::cout << std::setprecision(9) << std::setw(20) << std::setfill('_');
std::cout << d << std::endl;
   return 0;
}
greetings from: CROATIA
posted by: icopec
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
cin.getLine() function skips. Please help! unpopular C++ Programming 3 February 29th, 2008 11:50 AM
Determining Data type with CIN Bourne C++ Programming 2 March 23rd, 2007 05:40 PM
cin being skipped. ignore() not working UberNewf Visual C++ 0 June 28th, 2005 04:27 PM
Char array cin query (additional) gillianbc C++ Programming 3 October 29th, 2004 03:22 PM
cin.getline alfrepa Visual C++ 0 April 14th, 2004 08:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.