i have tried a program that it should show all words i typed, but it can't
e.g.
1 2 3
1 <--
2 <--
it always miss the last one
then i continue to type
4
3 <-- it shows now !!
However, if i change the loop into
while( in_iter != eof){
*out_iter++ = *in_iter;
++in_ter;
}
it will be fine, i don't know what happens to it.
************************************************** ***************
#include <iostream>
#include <iterator>
#include <string>
using namespace std;
int main()
{
ostream_iterator<stringout_iter(cout, "<\n");
istream_iterator<stringin_iter(cin), eof;
while( in_iter != eof ){
*out_iter++ = *in_iter++;
}
return 0; 2 1309
This is similar to
cout << *in_iter++;
Basically 3 things happen here
1. cout << operator is passed the value
2, increment operation takes place
3. message is flushed to output stream.
Tge problem is in the 2nd step when it increments and if it moves to
beginning of next stream input after all buffer reading is completed
and it goes to waiting state.
, then the 3rd step is not executed
Thanks,
Satish
tong wrote:
i have tried a program that it should show all words i typed, but it can't
e.g.
1 2 3
1 <--
2 <--
it always miss the last one
then i continue to type
4
3 <-- it shows now !!
However, if i change the loop into
while( in_iter != eof){
*out_iter++ = *in_iter;
++in_ter;
}
it will be fine, i don't know what happens to it.
************************************************** ***************
#include <iostream>
#include <iterator>
#include <string>
using namespace std;
int main()
{
ostream_iterator<stringout_iter(cout, "<\n");
istream_iterator<stringin_iter(cin), eof;
while( in_iter != eof ){
*out_iter++ = *in_iter++;
}
return 0;
Just one correction though, I am not sure of the 1st step but what I am
sure is before the message is flushed, the input iterator is
incremented. For example
cout << i++ << j++ << endl;//i++, j++ are all executed before message
is flushed out.
Thanks,
Satish
Satish wrote:
This is similar to
cout << *in_iter++;
Basically 3 things happen here
1. cout << operator is passed the value
2, increment operation takes place
3. message is flushed to output stream.
Tge problem is in the 2nd step when it increments and if it moves to
beginning of next stream input after all buffer reading is completed
and it goes to waiting state.
, then the 3rd step is not executed
Thanks,
Satish
tong wrote:
i have tried a program that it should show all words i typed, but it can't
e.g.
1 2 3
1 <--
2 <--
it always miss the last one
then i continue to type
4
3 <-- it shows now !!
However, if i change the loop into
while( in_iter != eof){
*out_iter++ = *in_iter;
++in_ter;
}
it will be fine, i don't know what happens to it.
************************************************** ***************
#include <iostream>
#include <iterator>
#include <string>
using namespace std;
int main()
{
ostream_iterator<stringout_iter(cout, "<\n");
istream_iterator<stringin_iter(cin), eof;
while( in_iter != eof ){
*out_iter++ = *in_iter++;
}
return 0;
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bill Rudolph |
last post by:
The member function basic_ios::operator!() returns the bool result of
the basic_ios::fail() function which is true if either failbit or
badbit is set (This is per p. 616 of TC++PL by B. Stroustrup...
|
by: NPC |
last post by:
Hi,
Is there any way to use an istream_iterator<> in a way which inserts each
element at the end of a newline character rather than a space character?
Could be it looks for any type of whitespace...
|
by: Alex Vinokur |
last post by:
------ foo.cpp : BEGIN ------
#include <cassert>
#include <vector>
#include <string>
#include <iostream>
#include <iterator>
#include <fstream>
using namespace std;
|
by: ben |
last post by:
Is istream_iterator<> and ostream_iterator<> supposed NOT to be included in
<iostream>? The following example compiles in VC 7.1 but not with gcc 3.4.3
#include <iostream>
#include <deque>...
|
by: Richo11 |
last post by:
This is probably a silly question but I am learning sorry...
I am trying to read in a series of strings from standard input using the istream_iterator member function, how does...
|
by: alberto |
last post by:
I am learning STL with the book STL Tutorial and Reference guide (1 edition),
the following example don't run :
int main()
{
// Initialize array a with 10 integers:
int a = {12, 3, 25, 7, 11,...
|
by: dragoncoder |
last post by:
Hi,
I am just a newbie in STL and trying to learn istream_iterator. My
problem is I want a program which will take a comma separated string
from the command line, tokenize it and copies into a...
|
by: Pradeep |
last post by:
Hi All,
I am facing some problem using istream_iterator for reading the
contents of a file and copying it in a vector of strings.However the
same thing works for a vector of integers.
The...
|
by: Juha Nieminen |
last post by:
I'm using gcc 3.3.5. This code:
std::set<std::stringt(std::istream_iterator<std::string>(std::cin),
std::istream_iterator<std::string>());
gives a strange error message:
error: cannot use...
|
by: Sam |
last post by:
Andre Paim writes:
Becase std::istream_iterator<chardoes not mean "return one character at a
time from a std::istream". It means "return the next element from a
std::istream, where each...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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: 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...
| |