473,396 Members | 2,068 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,396 software developers and data experts.

change the default separator in stream operator ">>" ?!?!?

Hi,

I've a question...
is it possible to change the default separator in the stream operator ">>"
(for example from the blank space " " to the comma "," ) ?
Here is an example...

I want to read a sequence separated by blank space. I can do like
this...(with cin, but with file is the same thing)

2003/08/15 25 26 24.23232323
----------------------------------------
std::string data;
int val1, val2;
float r1;

std::cout << "Insert data: ";
std::cin >> name >> val1 >> val2 >> r1;
------------------------------------------

But if I've comma separated values like....????

2003/08/15,25,26,24.23232323

I know that I can use the getline where it's possible to select the
separator, but my question is only about the ">>".
With all values different from char or string I can di something like
this...

char c;
cin >> val1 >> c >> val2 >> c >> r1;

but with a string.... I don't know.
Thanks for your opinions,
Ciao, Checco.
Jul 19 '05 #1
4 6033
In article <op**************@news.tin.it>, od********@tin.it says...
Hi,

I've a question...
is it possible to change the default separator in the stream operator ">>"
(for example from the blank space " " to the comma "," ) ?


http://www.google.com/groups?selm=MP...209ceaa989a43%
40news.clspco.adelphia.net

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #2
On Mon, 15 Sep 2003 14:43:39 GMT, Jerry Coffin <jc*****@taeus.com> wrote:
In article <op**************@news.tin.it>, od********@tin.it says...
Hi,

I've a question...
is it possible to change the default separator in the stream operator
">>" (for example from the blank space " " to the comma "," ) ?


http://www.google.com/groups?selm=MP...o.adelphia.net


Thanks,
even if with my current C++ knowledge is hard for me to understand ;)

I've thought there was something easier, I think I'll use the sstream and
the getline to tokenize the entire record as a string.

Thanks anyway.

Ciao, Checco

Jul 19 '05 #3
On Mon, 15 Sep 2003 15:00:04 GMT, Francesco <od********@tin.it> wrote:
On Mon, 15 Sep 2003 14:43:39 GMT, Jerry Coffin <jc*****@taeus.com> wrote:
In article <op**************@news.tin.it>, od********@tin.it says...
Hi,

I've a question...
is it possible to change the default separator in the stream operator
">>" (for example from the blank space " " to the comma "," ) ?


http://www.google.com/groups?selm=MP...o.adelphia.net


Thanks,
even if with my current C++ knowledge is hard for me to understand ;)

I've thought there was something easier, I think I'll use the sstream and
the getline to tokenize the entire record as a string.


Boost have a tokenizer class:

http://www.boost.org/libs/tokenizer/index.htm

Tom
Jul 19 '05 #4
On Mon, 15 Sep 2003 16:15:19 +0100, tom_usenet <to********@hotmail.com>
wrote:

Boost have a tokenizer class:

http://www.boost.org/libs/tokenizer/index.htm

Tom

Yes, I know, but I need full portability and I must use only standard
library.
But it's not so hard to take tokens...

std::vector<std::string> scomponi(std::string str, char separatore)
{
// assegnamento della stringa al tipo stringstream std::stringstream
dati(str); std::string buff;
std::vector<std::string> ris;

// divisione in tokens
while (getline(dati, buff, separatore))
ris.push_back(buff);
return ris;
}

Thanks.
Ciao, Checco.

Jul 19 '05 #5

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

Similar topics

1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
23
by: raj | last post by:
I used to remember why c++ needed both ? Could somebody help me here ? For example class A{ f(); }; A* aa;
1
by: mkalyan79 | last post by:
Hi, I wanted to find out what is the equivalent operator of ">>>" operator of java in C#. Thanks, K
3
by: MLH | last post by:
If I run ?", ","" in the immediate window, I get a comma followed by 13 spaces. It is difficult for me to understand this.
11
by: Holger | last post by:
Hi I have not been able to figure out how to do compound statement from C - "<test>?<true-val>:<false-val>" But something similar must exist...?! I would like to do the equivalent if python...
14
by: Jess | last post by:
Hi, I read about operator overloading and have a question regarding "operator->()". If I have two classes like this: struct A{ void f(); }; struct B{
5
by: planetbrett | last post by:
I have read through php.net manuals and have not see any mention about what these operands actually do. I have seen them used in a bunch of different code lately and don't really understand. ...
2
by: Colonel | last post by:
It seems that the problems have something to do with the overloading of istream operator ">>", but I just can't find the exact problem. // the declaration friend std::istream &...
4
by: dominique | last post by:
Hello All, In a wx GUI, I would like to let the user choose between >, < or =. So, I created a combobox and when the user chooses ">" for instance, I wanted to return (the objective is to send...
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: 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
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: 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
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
Oralloy
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,...
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
agi2029
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,...

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.