473,666 Members | 2,284 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::g etline() will include \r (13) character
ifstream::getli ne won't include \r

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

stringstream::g etline() will include \r (13) character
ifstream::getli ne 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::g etline() will include \r (13) character
ifstream::getli ne 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********@ter ra.es> ???????/???????? ? ???????? ?????????:
news:2f******** ****@uni-berlin.de...
Dmitri Zhukov wrote:
I've found out a difference between stringstream and ifstream objects:

stringstream::g etline() will include \r (13) character
ifstream::getli ne 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
14802
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 <iostream> #include <string> #include <sstream> #include <list>
1
4894
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
3730
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 in("in.txt"); if(!in) {cout << "error\n";} in.close(); if(!in) {cout << "error\n";} in.close(); if(!in) {cout << "error\n";}
2
12235
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
12162
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 << value << std::endl ; strbuf.flush(); DestinationType convalue; strbuf >> convalue;
14
4436
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 contents) my problem now is how can i grab all the file contents in one swoop and put it in a string for editing? I hate to go through the file and copy line by line:
1
3423
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 below shows what I'm trying to do: #include <stdio.h> #ifdef _WIN32 #include <io.h> #else
2
7845
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
3549
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. std::ifstream is("xml.txt"); if(is.fail()) { return 0;
0
8781
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7385
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6192
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
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 we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.