Changeset 7839f78
- Timestamp:
- Aug 10, 2023, 10:18:55 PM (16 months ago)
- Branches:
- master
- Children:
- 13600e8
- Parents:
- 9ff71ff
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r9ff71ff r7839f78 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Thu Jun 29 21:52:51202314 %% Update Count : 55 3313 %% Last Modified On : Thu Aug 10 21:24:07 2023 14 %% Update Count : 5570 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 3721 3721 \end{cquote} 3722 3722 The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators and newline. 3723 Similar simplification occurs for \Index{tuple} I/O, which flattens the tuple and prints each value separated by ``\lstinline[showspaces=true]{, }'' .3723 Similar simplification occurs for \Index{tuple} I/O, which flattens the tuple and prints each value separated by ``\lstinline[showspaces=true]{, }'' (comma space). 3724 3724 \begin{cfa} 3725 3725 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ]; … … 3751 3751 \end{tabular} 3752 3752 \end{cquote} 3753 Input and output use a uniform operator, ©|©, rather than \CC's ©>>© and ©<<© input/output operators.3754 3753 There is a weak similarity between the \CFA logical-or operator and the \Index{Shell pipe-operator} for moving data, where data flows in the correct direction for input but the opposite direction for output. 3754 Input and output use a uniform operator, ©|©, rather than \CC's ©<<© and ©>>© input/output operators, which prevents this common error in \CC: 3755 \begin{C++} 3756 cin << i; // why is this generating a lot of error messages? 3757 \end{C++} 3755 3758 3756 3759 For implicit formatted input, the common case is reading a sequence of values separated by whitespace, where the type of an input constant must match with the type of the input variable. … … 3855 3858 \Indexc{close} flushes the stream and closes the file. 3856 3859 \item 3857 \Indexc{write} (©ofstream© only) write ©size© bytes to the stream.3858 The bytes are written lazily to file when internal buffers fill.3860 \Indexc{write} (©ofstream© only) writes ©size© bytes to the stream. 3861 The bytes are written lazily when an internal buffer fills. 3859 3862 Eager buffer writes are done with ©flush© 3860 3863 \item 3861 \Indexc{read} (©ifstream© only) read ©size© bytes tothe stream.3864 \Indexc{read} (©ifstream© only) reads ©size© bytes from the stream. 3862 3865 \item 3863 3866 \Indexc{ungetc} (©ifstream© only) pushes the character back to the input stream. … … 3968 3971 3969 3972 \item 3970 If a space is desired before or after one of the special string start/end characters, simply insert a space.3973 If a space is desired before or after one of the special string start/end characters, explicitly insert a space. 3971 3974 \begin{cfa} 3972 3975 sout | "x ($\R{\texttt{\textvisiblespace}}$" | 1 | "$\R{\texttt{\textvisiblespace}}$) x" | 2 | "$\R{\texttt{\textvisiblespace}}$, x" | 3 | "$\R{\texttt{\textvisiblespace}}$:x:$\R{\texttt{\textvisiblespace}}$" | 4; … … 4073 4076 1, 2, 34, 5, 6 4074 4077 \end{cfa} 4075 ©sep© \emph{cannot} be used to start/end a line with a separator because separators do not appear at the start/end of a line ;4076 use ©sep© to accomplish this functionality.4078 ©sep© \emph{cannot} be used to start/end a line with a separator because separators do not appear at the start/end of a line. 4079 Use ©sep© to accomplish this functionality. 4077 4080 \begin{cfa}[belowskip=0pt] 4078 4081 sout | ®sep® | 1 | 2 | 3 | ®sep®; $\C{// sep does nothing at start/end of line}$ … … 4097 4100 \begin{enumerate}[parsep=0pt] 4098 4101 \item 4102 \Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} reads the newline character, when reading single characters. 4103 \item 4104 \Indexc{nlOff}\index{manipulator!nlOff@©nlOff©} does \emph{not} read the newline character, when reading single characters. 4105 \item 4099 4106 \Indexc{nl}\index{manipulator!nl@©nl©} scans characters until the next newline character, \ie ignore the remaining characters in the line. 4100 \item 4101 \Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} reads the newline character, when reading single characters. 4102 \item 4103 \Indexc{nlOff}\index{manipulator!nlOff@©nlOff©} does \emph{not} read the newline character, when reading single characters. 4107 If ©nlOn© is enabled, the ©nl© is also consumed. 4104 4108 \end{enumerate} 4105 4109 For example, in: … … 4113 4117 For output: 4114 4118 \begin{enumerate}[parsep=0pt] 4119 \item 4120 \Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} implicitly prints a newline at the end of each output expression. 4121 \item 4122 \Indexc{nlOff}\index{manipulator!nlOff@©nlOff©} does \emph{not} implicitly print a newline at the end of each output expression. 4115 4123 \item 4116 4124 \Indexc{nl}\index{manipulator!nl@©nl©} inserts a newline. … … 4129 4137 6 4130 4138 \end{cfa} 4131 Note, a terminating ©nl© is merged (overrides) with the implicit newline at the end of the ©sout© expression, otherwise it is impossible to print a single newline 4132 \item 4133 \Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} implicitly prints a newline at the end of each output expression. 4134 \item 4135 \Indexc{nlOff}\index{manipulator!nlOff@©nlOff©} does \emph{not} implicitly print a newline at the end of each output expression. 4139 Note, a terminating ©nl© is merged with (overrides) the implicit newline at the end of the ©sout© expression, otherwise it is impossible to print a single newline 4136 4140 \end{enumerate} 4137 4141 … … 4139 4143 \subsection{Output Value Manipulators} 4140 4144 4141 The following \Index{manipulator}s control formatting of output values (printing), and only affect the format of the argument.4145 The following \Index{manipulator}s control formatting (printing) of the argument output values. 4142 4146 \begin{enumerate} 4143 4147 \item … … 4154 4158 \begin{cfa}[belowskip=0pt] 4155 4159 sout | oct( 0 ) | oct( 27HH ) | oct( 27H ) | oct( 27 ) | oct( 27L ); 4156 0033 033 033 0334160 ®0® 033 033 033 033 4157 4161 sout | oct( -27HH ) | oct( -27H ) | oct( -27 ) | oct( -27L ); 4158 4162 0345 0177745 037777777745 01777777777777777777745 … … 4164 4168 \begin{cfa}[belowskip=0pt] 4165 4169 sout | hex( 0 ) | hex( 27HH ) | hex( 27H ) | hex( 27 ) | hex( 27L ); 4166 0 0x1b 0x1b 0x1b 0x1b4170 0x0 0x1b 0x1b 0x1b 0x1b 4167 4171 sout | hex( -27HH ) | hex( -27H ) | hex( -27 ) | hex( -27L ); 4168 4172 0xe5 0xffe5 0xffffffe5 0xffffffffffffffe5 4169 4173 4170 4174 sout | hex( 0.0 ) | hex( 27.5F ) | hex( 27.5 ) | hex( 27.5L ); 4171 0x0 .p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+14175 0x0p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+1 4172 4176 sout | hex( -27.5F ) | hex( -27.5 ) | hex( -27.5L ); 4173 4177 -0x1.b8p+4 -0x1.b8p+4 -0xd.cp+1 … … 4413 4417 Instead, the next sequence of non-whitespace characters are read, and the input sequence is terminated with delimiter ©'\0'©. 4414 4418 The string variable \emph{must} be large enough to contain the input sequence. 4415 4416 The following \Index{manipulator}s control formatting of input values (reading), and only affect the format of the argument. 4417 4419 To force programmers to consider buffer overruns for C-string input, C-strings can only be read with a width field, which should specify a size less than or equal to the C-string size, \eg: 4420 \begin{cfa} 4421 char line[64]; 4422 sin | wdi( ®sizeof(line)®, line ); // must specify size 4423 \end{cfa} 4424 4425 A scanset is a simple regular expression, where the matching set contains any Latin-1 character (8-bits) or character ranges using minus. 4426 For example, the scanset \lstinline{"a-zA-Z -/?§"} matches characters between ©'a'© and ©'z'©, between ©'A'© and ©'Z'©, between space and ©'/'©, and characters ©'?'© and (Latin-1) ©'§'©. 4427 The following string is matched by this scanset: 4428 \begin{cfa} 4429 !&%$ abAA () ZZZ ?? xx§§§§ 4430 \end{cfa} 4431 To match a minus, put it as the first character, ©"-0-9"©. 4432 Note, other complex forms of regular-expression matching is not supported. 4433 4434 The following \Index{manipulator}s control scanning of input values (reading), and only affect the format of the argument. 4418 4435 \begin{enumerate} 4419 4436 \item … … 4458 4475 4459 4476 \item 4460 \Indexc{incl}( scanset, input-string )\index{manipulator!incl@©incl©}4461 For C-string types , the scanset matches any number of characters \emph{in} the set.4477 \Indexc{incl}( scanset, wdi-input-string )\index{manipulator!incl@©incl©} 4478 For C-string types only, the scanset matches any number of characters \emph{in} the set. 4462 4479 Matching characters are read into the C input-string and null terminated. 4463 4480 \begin{cfa}[belowskip=0pt] … … 4470 4487 4471 4488 \item 4472 \Indexc{excl}( scanset, input-string )\index{manipulator!excl@©excl©}4489 \Indexc{excl}( scanset, wdi-input-string )\index{manipulator!excl@©excl©} 4473 4490 For C-string types, the scanset matches any number of characters \emph{not in} the set. 4474 4491 Non-matching characters are read into the C input-string and null terminated. … … 4480 4497 ®xyz®bca 4481 4498 \end{cfa} 4499 4500 \item 4501 \Indexc{getline}( char delimit, wdi-input-string )\index{manipulator!getline@©getline©} 4502 Is an @excl@ with scanset ©"delimit"©, which consumes all characters up to the delimit character. 4503 If the delimit character is omitted, it defaults to ©'\n'© (newline). 4482 4504 \end{enumerate} 4483 4505
Note: See TracChangeset
for help on using the changeset viewer.