473,978 Members | 2,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

~traits::eof()?

Good day,

What is the safest way to get a non-end of file value?
char_traits<cha r_type>::eof() will get me eof, but how can I safely and
consistently generate a value that is not eof? should i use
~char_traits<ch ar_type>::eof() ? char_traits<cha r_type>::int_ty pe()?
char_traits<cha r_type>::eof() + 1?
while(!char_tra its<char_type>: :not_eof(char_t raits<char_type >::int_type(ran d())))?

mark

Jul 22 '05
12 2463

P.J. Plauger wrote:
the like. but is there no simple way to generate a value of type
char_traits<c har_type>::int_ type that is guaranteed to satisfy
char_traits<c har_type>::not_ eof()?

Only if you have a candidate "character" in hand that you assuredly
want *not* turned into an eof. That's what not_eof is for.


am i the only one that finds that odd? if you have a candidate
"character" (int_type) in hand, and you want to be assured that you do
not have eof, wouldn't it have been more straightforward to have:

int_type d = eq_int_type(c, eof()) ? not_eof_charact er() : c;

at least then d is well defined.
That's a helluva way to earn royalties, adding a nonstandard patch
to a kludge to an inelegant design.


hey, i wouldn't be the first!
int_type overflow(int_ty pe c = traits::eof())
{
// whatever
return (success) ? traits::not_eof (c) : traits::eof();
}

would that be guaranteed to work as expected?

Once you permit a valid character code to pun with eof(), it's hard
to say what "work" means anymore.


sorry, what was that? just in case i wasn't clear, this overflow() is
basic_streambuf ::overflow(). basic_streambuf ::overflow() is supposed to
return eof() on failure, anything else otherwise (exactly what is
unspecified). the input character may be eof().

what way is there to possibly satisfy these conditions besides the line
above (or does that not work either)?

mark

Jul 22 '05 #11

P.J. Plauger wrote:
ah, so traits::eof() can never be 0. perfect. thank you.

How did you deduce that? It's almost certainly true, but I doubt
that it's guaranteed.


by assuming that i could use the result of not_eof() in a boolean
expression, which i now realize was not correct. the name threw me off
:/ sorry.

if all not_eof() is good for is guaranteeing a non-eof value, why does
it need the parameter? is it that worth the little convenience of
getting back a known result *most* of the time?

mark

Jul 22 '05 #12
"Mark A. Gibbs" <x_*********@ro gers.com_x> wrote in message
news:F2******** *************@t wister01.bloor. is.net.cable.ro gers.com...
P.J. Plauger wrote:
the like. but is there no simple way to generate a value of type
char_traits<c har_type>::int_ type that is guaranteed to satisfy
char_traits<c har_type>::not_ eof()?

Only if you have a candidate "character" in hand that you assuredly
want *not* turned into an eof. That's what not_eof is for.


am i the only one that finds that odd? if you have a candidate
"character" (int_type) in hand, and you want to be assured that you do
not have eof, wouldn't it have been more straightforward to have:

int_type d = eq_int_type(c, eof()) ? not_eof_charact er() : c;

at least then d is well defined.


You're not the only one. See my comment immediately below.
That's a helluva way to earn royalties, adding a nonstandard patch
to a kludge to an inelegant design.


hey, i wouldn't be the first!
int_type overflow(int_ty pe c = traits::eof())
{
// whatever
return (success) ? traits::not_eof (c) : traits::eof();
}

would that be guaranteed to work as expected?

Once you permit a valid character code to pun with eof(), it's hard
to say what "work" means anymore.


sorry, what was that? just in case i wasn't clear, this overflow() is
basic_streambuf ::overflow(). basic_streambuf ::overflow() is supposed to
return eof() on failure, anything else otherwise (exactly what is
unspecified). the input character may be eof().

what way is there to possibly satisfy these conditions besides the line
above (or does that not work either)?


IIRC, you were muddling in the possibility that eof() could return zero.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
8147
by: Kevin Saff | last post by:
Why are these two similar functions provided? (unget & putback) I'm working with a file format where the type of record to read in next is stored in the first two bytes of the record. From a design standpoint, I wanted the class general enough to handle longer/more complex keys, so I thought I should store this key value in the record class itself, and query the record types by a "canRead(std::istream&)" function. This would
2
3164
by: | last post by:
Sory about stupid question. What are differences between uflow and underflow functions ? Pls explains. Tks
3
2313
by: Christopher Benson-Manica | last post by:
Unless there is something wrong with the following complete C++ file, I think my quest to stream-ize our code will be at an end :( #include <sstream> #include <iostream> using namespace std; class linebuf : public streambuf {
18
8281
by: Amadeus W. M. | last post by:
I'm trying to read a whole file as a single string, using the getline() function, as in the example below. I can't tell what I'm doing wrong. Tried g++ 3.2, 3.4 and 4.0. Thanks! #include <iostream> #include <fstream> #include <cstdlib> #include <string>
2
414
GCC
by: Bo Hunter | last post by:
GCC 3.2 Redhat 9 Why does GCC have a problem with this? if( !( s1 >> Num( base, value )).eof() || ... I have to create a named Num object and everthing is fine.
6
5306
by: Dave | last post by:
In .Net 2003 if a line, read from a text file is larger than a size parameter, the ifstream getline(buff, sze) put the file pointer to the EOF, so next peek() returns EOF. I saw this problem also when size was 2000 but line was 1200 bytes long. There is no such problem with .Net 2002 For .Net 2003 I used : #include <string> #include <fstream>
13
3752
by: Randy | last post by:
Is there any way to do this? I've tried tellg() followed by seekg(), inserting the stream buffer to an ostringstream (ala os << is.rdbuf()), read(), and having no luck. The problem is, all of these methods EXTRACT the data at one point or another. The other problem is there appears to be NO WAY to get at the actual buffer pointer (char*) of the characters in the stream. There is a way to get the streambuf object associated with the...
15
3027
by: waltbrad | last post by:
Hello. I'm studying the book "C++ Primer Plus" by Stephan Prata. In chapter 6 he gives an exercise that reads from a file. The list is thus: 4 Sam Stone 2000 Freida Flass 100500 Tammy Tubbs
2
2200
by: Arcturus | last post by:
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkh6waMACgkQq5h2IFR18WMFrwCgv/PNAC8FTZCErvc0KHnx0zpC KhcAnjl/xFAEJb056UdQaCZqPfnGbqA+ =0Y8B -----END PGP SIGNATURE----- -----BEGIN PGP SIGNATURE-----
0
10178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11835
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11596
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10922
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10089
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8466
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
5163
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.