ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
string4.cpp
Go to the documentation of this file.
1 
8 #include <fvar.hpp>
9 #include <stdlib.h>
10 
17 istream& operator>>(istream& c, adstring& t)
18 {
19  const unsigned int max_length = 1024;
21  char tmp[max_length + 3];
22  tmp[max_length + 1] = '\0';
23  c >> tmp;
24  if (tmp[max_length + 1] != '\0')
25  {
26  cerr << "Error -- Maximum adstring length exceeded in "
27  << "istream& operator>>(istream&, adstring&)" << endl;
28  ad_exit(1);
29  }
30  t = tmp;
31 
32  return c;
33 }
40 istream& operator>>(istream& c, line_adstring& t)
41 {
42  const unsigned int max_length = 1025;
43  char tmp[max_length + 1];
44 
45  // throw away the newline at the end of the last line if necessary
46  //if (ch == '\r') ch = (char)c.get();
47 
48  unsigned int ii = 0;
49  while (ii <= max_length)
50  {
51  char ch = (char)c.get();
52  if (ch == '\r')
53  {
54  char p = (char)c.peek();
55  if (p == '\n')
56  {
57  ch = (char)c.get();
58  }
59  break;
60  }
61  else if (ch == '\n')
62  {
63  break;
64  }
65  else if (ch == EOF)
66  {
67  break;
68  }
69  else
70  {
71  tmp[ii++] = ch;
72  }
73  }
74  if (ii > max_length)
75  {
76  cerr << "Error -- Maximum line_adstring length exceeded in "
77  << "istream& operator>>(istream&, line_adstring&)" << endl;
78  ad_exit(1);
79  }
80  tmp[ii] = '\0';
81  t = tmp;
82 
83  return c;
84 }
exitptr ad_exit
Definition: gradstrc.cpp:53
prnstream & endl(prnstream &)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
istream & operator>>(const istream &input, const d3_array &arr3)
Read values from input stream into arr3.
Definition: d3_io.cpp:60