473,408 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Interpret istringstream::tellg as character position?

I'm using the stringstreams to get the numerical values of string
tokens (the strings result from tokenizing a line of input elsewhere):

#include <iostream>
#include <sstream>
using namespace std;

int main(void)
{
istringstream iss("1.23DOG");
float flt;

cout << "isspos0=" << iss.tellg() << "\n" ;
iss >> flt;
cout << "flt=" << flt << "\n";
cout << "isspos0=" << iss.tellg() << "\n" ;
return 0;
};

This generates:

isspos0=0
flt=1.23
isspos0=4

I'm reading lots of warnings against interpreting tellg() as a an
integral type, or as a byte offset from the beginning of the stream.
This seems to be in the context of multibyte file streams, or file
streams in microsoft text files, where two bytes are used to signify
the end of line.

For my purposes, I just want to use tellg() to determine if there are
any residual characters left in the token, in which case I consider
the token to be illegal. Is this "evil"? I don't anticipate dealing
with multibyte data.

Thanks.

Fred
--
Fred Ma, fm*@doe.carleton.ca
Dept. of Electronics, Carleton University, Ottawa, Ontario, Canada
Jul 22 '05 #1
2 2676

"Fred Ma" <fm*@doe.carleton.ca> wrote in message
news:40***************@doe.carleton.ca...
I'm using the stringstreams to get the numerical values of string
tokens (the strings result from tokenizing a line of input elsewhere):

#include <iostream>
#include <sstream>
using namespace std;

int main(void)
{
istringstream iss("1.23DOG");
float flt;

cout << "isspos0=" << iss.tellg() << "\n" ;
iss >> flt;
cout << "flt=" << flt << "\n";
cout << "isspos0=" << iss.tellg() << "\n" ;
return 0;
};

This generates:

isspos0=0
flt=1.23
isspos0=4

I'm reading lots of warnings against interpreting tellg() as a an
integral type, or as a byte offset from the beginning of the stream.
This seems to be in the context of multibyte file streams, or file
streams in microsoft text files, where two bytes are used to signify
the end of line.

For my purposes, I just want to use tellg() to determine if there are
any residual characters left in the token, in which case I consider
the token to be illegal. Is this "evil"? I don't anticipate dealing
with multibyte data.


I guess not but why not try to read one more character? If that succeeds you
know you have an invalid token. Seems a little less opaque as well.

john
Jul 22 '05 #2
John Harrison wrote:

"Fred Ma" <fm*@doe.carleton.ca> wrote:
I'm using the stringstreams to get the numerical values of string
tokens (the strings result from tokenizing a line of input elsewhere)
<...snip...>
I'm reading lots of warnings against interpreting tellg() as a an
integral type, or as a byte offset from the beginning of the stream.
This seems to be in the context of multibyte file streams, or file
streams in microsoft text files, where two bytes are used to signify
the end of line.

For my purposes, I just want to use tellg() to determine if there are
any residual characters left in the token, in which case I consider
the token to be illegal. Is this "evil"? I don't anticipate dealing
with multibyte data.


I guess not but why not try to read one more character? If that succeeds you
know you have an invalid token. Seems a little less opaque as well.

Uhm....I didn't think of it. Good idea. Thanks.

Fred
--
Fred Ma, fm*@doe.carleton.ca
Dept. of Electronics, Carleton University, Ottawa, Ontario, Canada
Jul 22 '05 #3

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

Similar topics

7
by: WindAndWaves | last post by:
Hi Folk Here I am writing my first php / mysql site, almost ready, and now this... charactersets.... The encoding that I use on my webpage is: <META HTTP-EQUIV="content-type"...
4
by: Justin Carter | last post by:
Hi. I'm using VB6 and trying to read in a simple text file. I'm using a statement similar to the following, which generally works fine. Input #Item, variable1, variable2, variable3, etc. ...
3
by: bml | last post by:
Could you help and answer my questions of istringstream? Thanks a lot! 1. Reuse an "istringstream" istringstream ist; ist.str("This is FIRST test string"); ist.str("This is SECOND test...
7
by: Luther Baker | last post by:
Hi, My question is regarding std::istringstream. I am serializing data to an ostringstream and the resulting buffer turns out just fine. But, when I try the reverse, when the istringstream...
6
by: JustSomeGuy | last post by:
I am passing an istringstream to a function. I want that function to get a copy of the istringstream and not a refrence to it. ie when the function returns I want the istringstream to be...
18
by: Robert Bowen | last post by:
Hello peeplez. I have an odd problem. When I put the ANSI symbol for "less than" ("<"), the word STRONG and then the ANSI symbol for "greater than" (">") in my web page, followed by some text, then...
10
by: k:arel | last post by:
today i've discovered the istringstream object i'm trying to read a string and split it up in a number of fields, consisting of integers and strings it's for a protocol that sends messages with:...
1
by: KK | last post by:
Dear comp.lang.c++, The code below reads off strings of a file into a vector. ifstream srcfile("c:\\test.txt"); istream_iterator<stringstrIter(srcfile), eos; vector<string strvec(strIter, eos);...
14
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.