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

question about skipws manipulator

// ws manipulator example
#include <iostream>
#include <sstream>
using namespace std;

int main () {
char a[10], b[10], c[10];

istringstream iss (" one \n \t two");
iss >noskipws;
iss >a >skipws >b >c;
cout << a << "," << b <<"."<<c<< endl;

return 0;
}
----------------------------
I expected the above code will output " ,one.two",
but it is ",."
I think a=" "; -noskipws
b="one"; --skipws
c="two"; --skipws

Anything I missed?
Nov 5 '08 #1
1 2767
thomas wrote:
// ws manipulator example
#include <iostream>
#include <sstream>
using namespace std;

int main () {
char a[10], b[10], c[10];

istringstream iss (" one \n \t two");
iss >noskipws;
iss >a >skipws >b >c;
cout << a << "," << b <<"."<<c<< endl;

return 0;
}
----------------------------
I expected the above code will output " ,one.two",
but it is ",."
I think a=" "; -noskipws
b="one"; --skipws
c="two"; --skipws

Anything I missed?
You didn't initialise your arrays. You didn't check the failbit after
the input operation. Try this:
===========================
// ws manipulator example
#include <iostream>
#include <sstream>
using namespace std;

int main () {
char a[10] = {}, b[10] = {}, c[10] = {};

istringstream iss (" one \n \t two");
iss >noskipws;
if (iss >a) {
if (iss >skipws >b) {
if (iss >c)
cout << "everything was converted OK\n";
else
cerr << "error reading 'c'\n";
}
else
cerr << "error reading 'b'\n";
}
else
cerr << "error reading 'a'\n";

cout << a << "," << b <<"."<<c<< endl;

return 0;
}
===========================
I get "error reading 'a'", and am guessing you need to read more about
'noskipws' and its effects on the input operations...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 5 '08 #2

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

Similar topics

10
by: Paul Schneider | last post by:
I want to sort a class derived from std::vector with STL sort.: template<typename T, typename fitParaType, typename fitResType> class Manipulator{ // shouldn't I now be able to access private...
1
by: berkay | last post by:
hi all,can anyone send me a good example that teaches of using skipws,it may be about file operations
8
by: stoptv | last post by:
Hello group, this is my dilemma: ------------------------------------------------------------------------ #include <iostream> using namespace std; // a regular manipulator ostream & hello(...
2
by: Norman Landis | last post by:
This is something that has puzzled me for a while. How does C++ define skipws and noskipws in such a way that they can be used as pseudo-variables that setf and unsetf a flag? The reason I ask...
6
by: jack | last post by:
I have a class which overloads the insertion operator '<<' for every type that ostream handles. I do this so that I can use my class a direct replacement for cout and cerr where the insertion...
32
by: Axel Bock | last post by:
Hi all, I am trying to get my head around what happens if I return a class object from a function. It seems C++ (MinGW) does not invoke the copy constructor if I do something like this: ...
9
by: barcaroller | last post by:
When I use an iostream manipulator in a cout statement, it seems to affect all subsequent cout statements. cout << x << endl; // dec by default cout << hex << x << endl; // hex cout <<...
6
by: Jojo | last post by:
Hi all, I was wondering how I can perform formatted output with C++ strings. For example, suppose I have in plain C: sprintf(C_string, "%5.2f %6d"); How can I do such a thing with C++...
1
by: thomas | last post by:
// ws manipulator example #include <iostream> #include <sstream> using namespace std; int main () { char a, b, c; istringstream iss (" one \n \t two"); iss >noskipws;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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?
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...

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.