473,394 Members | 1,641 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,394 software developers and data experts.

how to check whether istringstream object has empty buffer?

Hi,

What would be the best way to check whether an istringstream object has
empty buffer? I wanted to do something like:

istringstream isStr(myStringContent.c_str());
while (isStr_BUFFER_IS_NOT_EMPTY) {
//do something
}

I wanted to know how to implement isStr_BUFFER_IS_NOT_EMPTY. I did some
research on the google but still couldn't find a direct answer. I very
much appreciate your help.

Mingsheng

Jul 23 '05 #1
2 3101
mshngo wrote:
Hi,

What would be the best way to check whether an istringstream object has
empty buffer? I wanted to do something like:

istringstream isStr(myStringContent.c_str());
while (isStr_BUFFER_IS_NOT_EMPTY) {
//do something
}

I wanted to know how to implement isStr_BUFFER_IS_NOT_EMPTY. I did some
research on the google but still couldn't find a direct answer. I very
much appreciate your help.

Mingsheng


reading with >> sets the stream status depending on wether the read was
successful or not. If you read it to a string it shouldn't (as far as I
know) fail unless the buffer is empty.

so for example this crappy code I made quickly to test it

#include <iostream>
#include <string>
#include <sstream>

int main() {

std::string blah = "blah blah";
std::istringstream isStr(blah.c_str());
while( isStr >> blah ) {

std::cout << "blah" << std::endl;
}

std::cout << "bleh" << std::endl;
return 0;

}

outputs

blah
blah
bleh

- Jonne Lehtinen
Jul 23 '05 #2
On 7 May 2005 14:50:11 -0700, "mshngo" <ms****@gmail.com> wrote:
Hi,

What would be the best way to check whether an istringstream object has
empty buffer? I wanted to do something like:
Check out basic_ios::rdbuf (which returns a pointer to the stream's
buffer) and basic_streambuf::in_avail (which returns the number of
unread characters in a buffer). Usage looks like:
while (isStr.rdbuf()->in_avail()) {/* do stuff */}
istringstream isStr(myStringContent.c_str());
while (isStr_BUFFER_IS_NOT_EMPTY) {
//do something
}

I wanted to know how to implement isStr_BUFFER_IS_NOT_EMPTY. I did some
research on the google but still couldn't find a direct answer. I very
much appreciate your help.

I also recommend that you consider the approach Jonne Lehtinen
suggested. Depending on what you hope to accomplish, checking for
error after extraction may be more appropriate than checking for
available characters.

Kanenas
Jul 23 '05 #3

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

Similar topics

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...
19
by: wetherbean | last post by:
Hi group..I am writing a playlist management protocol where I have a file that holds all the playlists and a file that holds all the songs....before a playlist is created I need to check to see if...
7
by: mathieu | last post by:
Hello, Is there a way to construct a std::istringstream from a buffer of char and avoid copying the array of bytes ? const char s = "Hello, World"; std::string str(s); std::istringstream is;...
0
by: rbottone | last post by:
Since the strstream classes will be deprecated in the future, I have been looking for an alternative to this class for performing binary I/O. stringstream indicates that you can use...
173
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc....
2
by: rolan | last post by:
I'm trying to figure out how to convert an array of type "string" into integers, and I have begun using istringstream. I made a program to test how istringstream works, and I've been having...
12
by: sergey.lukoshkin | last post by:
Hello everyone! My task is in converting numbers from string to int variables. I used istringstream to perform it. So I wrote simple test function. But it doesn't work as I expected because...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.