473,508 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stringstream vs ifstream - one BIG difference

Hi all,

I've found out a difference between stringstream and ifstream objects:

stringstream::getline() will include \r (13) character
ifstream::getline won't include \r

I wonder how come. Is it prescribed behavior?
Jul 22 '05 #1
3 8621
Dmitri Zhukov wrote:
I've found out a difference between stringstream and ifstream objects:

stringstream::getline() will include \r (13) character
ifstream::getline won't include \r


fstream objects when not in binary mode does translation of line ending
conventions of the operating system. Other streams don't do that.

--
Salu2
Jul 22 '05 #2
"Dmitri Zhukov" <di*****@yandex.ru> wrote in message
news:c7**********@alpha2.radio-
stringstream::getline() will include \r (13) character
ifstream::getline won't include \r


Did you open your ifstream in ios::binary mode. If so, then I think it
should also contain the \r. Now I haven't tried this, so someone please
correct me if I am wrong. Thanks.
Jul 22 '05 #3

Cool. Thank u.

"Julián Albo" <JU********@terra.es> ???????/???????? ? ???????? ?????????:
news:2f************@uni-berlin.de...
Dmitri Zhukov wrote:
I've found out a difference between stringstream and ifstream objects:

stringstream::getline() will include \r (13) character
ifstream::getline won't include \r


fstream objects when not in binary mode does translation of line ending
conventions of the operating system. Other streams don't do that.

--
Salu2

Jul 22 '05 #4

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

Similar topics

3
14777
by: Mike Chirico | last post by:
Sorry about the newbie question. What's the best way to convert numbers to strings in C++. The following works, but is it better than using the sprintf() "old C" way of converting? #include...
1
4876
by: KidLogik | last post by:
Hello! I am using std::stringstream && std::string to parse a text file -> std::ifstream in; std::string s; std::streamstring ss; int n; I grab each line like so -> std::getline(in,s);
4
3721
by: hall | last post by:
Hi. I ran across a bug in one of my problems and after spending some time tracking it down i found that the problem arose in a piece of code that essentially did this: ----------- ifstream...
2
12158
by: Ney André de Mello Zunino | last post by:
Hello. Is g++ 3.3.3 (Cygwin) correct in rejecting the following test program? #include <istream> #include <sstream> #include <fstream> void test(std::istream& source) {
4
12136
by: Vijai Kalyan | last post by:
I wrote the following function as a curiosity: template<typename SourceType, typename DestinationType> DestinationType NumericCast(const SourceType& value) { std::wstringstream strbuf; strbuf...
14
4421
by: cpisz | last post by:
I want to do some find and erase operations that i find in the string class, upon the entire text contents of a file. I made a function that will take a string (designed to hold the entire file...
1
3410
by: FabioAng | last post by:
I implemented a codecvt facet (extracted from TCPL) but while it works well with 'ifstream' it doesn't work at all with 'stringstream'. Am I missing anything ? I tested it with MSVC 7.1 The code...
2
7821
by: david.crow | last post by:
Given the following input file: bob 1 2 3 4 5 mary 2 3 4 5 6 7 susan 3 4 5 6 7 8 9 This code snippet does not read it correctly: class Student {
3
3515
MrPickle
by: MrPickle | last post by:
I have a tag like so: <foo> and I am trying to extract 'foo' from this. I'm using a stringstream in a while loop but it seems to fail with the first line, then it works with every other line. ...
0
7225
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
7123
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
7324
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,...
1
7042
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
7495
tracyyun
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...
0
5627
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,...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
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 ...
0
418
bsmnconsultancy
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...

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.