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.carleto n.ca
Dept. of Electronics, Carleton University, Ottawa, Ontario, Canada 2 2694
"Fred Ma" <fm*@doe.carlet on.ca> wrote in message
news:40******** *******@doe.car leton.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
John Harrison wrote: "Fred Ma" <fm*@doe.carlet on.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.carleto n.ca
Dept. of Electronics, Carleton University, Ottawa, Ontario, Canada This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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" CONTENT="text/html; charset=UTF-8">
When people enter new data I use
|
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.
The problem is that one of the strings that is read in, variable2 in
the above example, is a square symbol, . An error is thrown, and I
can't find a way to work around it. (I'm stuck reading in that
symbol, i.e. I can't just change it in the text...
|
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 string");
cout << ist.str() << endl;
|
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 encounters the two
byte shorts, it either thinks it has reached the null terminator? or
eof and consequently stops reading values back in. It doesn't matter
whether or not I use the std::ios::binary flag when opening the
istringstream or the...
|
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
unmodified...
However when I try to pass it
fn(istringstream s) // doesn't compile
but
fn(istringstream & s) // does.
| |
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 close
the STRONG tag the same way, my text appears in bold. No problem.
When I do the same things with the corresponding HTML tags (< ,
> ) the tag is not interpreted, it is simply displayed:
<STRONG>text</STRONG>
|
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:
* message code, pe. 1 for HELLO
* message content, pe. 5 (seed)
both field are separated by @+@
|
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);
say the file has the following data
c:\\test.txt
---------------
|
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.
|
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,...
|
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...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |