How can I identify a carriage return in C++?
\r, \f, \0, \n, \t does not work. I have also tried !isprint(ch), iscntrl(ch), isspace(ch), etc....with no luck!
I even poked around in the MSDN and found some code that MS claims will save a file in unix format and I cut and pasted into my program(and made changes to suit):
.....
char ch;
char temp[MAX_PATH]="\0";
//Open the file for reading in binarymode.
ifstream fp_read(filenam e.c_str(), ios_base::in
| ios_base::binar y);
if(!fp_read)
cout << "could not open " << filename.c_str( ) << endl;
else
cout << "opened for read: " << filename.c_str( ) << endl;
sprintf(temp, "%s.temp", filename.c_str( ));
//Create a temporary file for writing in the binary mode. This
//file will be created in the same directory as the input file.
ofstream fp_write(temp, ios_base::out
| ios_base::trunc
| ios_base::binar y);
if(!fp_write)
cout << "could not open fp_write" << endl;
else
cout << "opened fp_write " << endl;
while(fp_read.e of() != true)
{
fp_read.get(ch) ;
//Check for CR (carriage return)
if((int)ch == 0x0D)
continue;
if (!fp_read.eof() )fp_write.put(c h);
}
fp_read.close() ;
fp_write.close( );
//Delete the existing input file.
remove(filename .c_str());
//Rename the temporary file to the input file.
rename(temp, filename.c_str( ));
//Delete the temporary file.
remove(temp);
.....
This does not work either.
Is there a sequence of characters that can be used to compare to a MS carriage return?
Thanks
Laura 6 17597
"Laura D" <an*******@disc ussions.microso ft.com> wrote: How can I identify a carriage return in C++?
What do you mean?
A carriage return can be specified with '\r' or (char)13.
On Windows, end of line indicators are carriage returns followed by
line feeds ("\r\n").
On *nix, end of line indicators are just line feeds - '\n' or
(char)10.
I have collected strings from a comma separated file generated by Excel and stored them in a deque<deque<str ing>> FileInStringTok ens. When I compare these strings one by one to "\r\n", I get nothing. But when I print FileInStringTok ens to a output file, the carriage returns are in fact there
"Laura D" <an*******@disc ussions.microso ft.com> wrote: I have collected strings from a comma separated file generated by Excel and stored them in a deque<deque<str ing>> FileInStringTok ens. When I compare these strings one by one to "\r\n", I get nothing. But when I print FileInStringTok ens to a output file, the carriage returns are in fact there?
Perhaps, then, what you're using to read from the file converts all
CR+LFs to either single LFs or single CRs, and converts them back on
writing to the file.
You could verify this by debugging of course...
I'll keep looking
Thanks.
More importantly, why are we discussing C++ in a C# NG?
BW
"Laura D" <an*******@disc ussions.microso ft.com> wrote in message
news:22******** *************** ***********@mic rosoft.com... How can I identify a carriage return in C++? \r, \f, \0, \n, \t does not work. I have also tried !isprint(ch),
iscntrl(ch), isspace(ch), etc....with no luck! I even poked around in the MSDN and found some code that MS claims will
save a file in unix format and I cut and pasted into my program(and made
changes to suit): ... char ch; char temp[MAX_PATH]="\0";
//Open the file for reading in binarymode. ifstream fp_read(filenam e.c_str(), ios_base::in | ios_base::binar y);
if(!fp_read) cout << "could not open " << filename.c_str( ) << endl; else cout << "opened for read: " << filename.c_str( ) << endl;
sprintf(temp, "%s.temp", filename.c_str( )); //Create a temporary file for writing in the binary mode. This //file will be created in the same directory as the input file. ofstream fp_write(temp, ios_base::out | ios_base::trunc | ios_base::binar y);
if(!fp_write) cout << "could not open fp_write" << endl; else cout << "opened fp_write " << endl;
while(fp_read.e of() != true) { fp_read.get(ch) ; //Check for CR (carriage return) if((int)ch == 0x0D) continue; if (!fp_read.eof() )fp_write.put(c h); }
fp_read.close() ; fp_write.close( ); //Delete the existing input file. remove(filename .c_str()); //Rename the temporary file to the input file. rename(temp, filename.c_str( )); //Delete the temporary file. remove(temp); ... This does not work either. Is there a sequence of characters that can be used to compare to a MS
carriage return? Thanks Laura
> Is there a sequence of characters that can be used to compare to a MS
carriage return?
There is no such thing a a Microsoft carriage return :-).
Skimming your code I notice you are opening the file as binary. All you may
be looking for is opening it as text and use a ReadLine kind of method to
read lines one by one. Have another look at that file open method and its
options.
And this is the C# group, not C++.
Martin. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Canes_Rock |
last post by:
The information posted at:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=slrnarv28n.e4j.TuxTrax%40fortress.tuxnet&rnum=1&prev=/groups%3Fq%3Dsuppress%2Bcarriage%2Breturn%2Bgroup:comp.lang.python.*%26hl%3Den%26lr%3D%26ie%3DUTF-8%26group%3Dcomp.lang.python.*%26selm%3Dslrnarv28n.e4j.TuxTrax%2540fortress.tuxnet%26rnum%3D1
seemed to provide a solution to eliminating the line feed and causing
a carriage return for the text displayed...
|
by: Andrew Chanter |
last post by:
I have a VBA function that returns a string including "vbcr" (VB Carriage
Return) to seperate a list into multiple rows, eg Item1 & vbcr & Item2 &
vbcr & Item3
This works as planned in the immediate window, producing a list where a
Carriage Return follows each item. But when I output the result into either
an Access query or form, instead of carriage returns I get little square
symbols between each of the items. Is anyone able to tell...
|
by: chrissmith_76_Fed_Up_With_Spam |
last post by:
Hello all,
I am using Access 2002, with file format of Access 2000, and am
experiencing a problem.
I have a subform that is shown in datasheet view for users to edit data
direct to a table.
When a user presses the Enter (or Return) key a carriage return is made
in the cell, rather than the cursor moving to the next field, which is
|
by: eagleofjade |
last post by:
I am trying to import data from a Word document into an Access table
with VBA.
The Word document is a form which has various fields. One of the fields
is a field for notes. In some cases, this note field contains carriage
returns.
When I import a note field that has carriage returns, what shows up in
the Access field are vertical black lines where the carriage return
should be.
|
by: David Cho |
last post by:
I am using this expression
\d+(,\s*\d+)*
to allow only numbers and commas. But if there are carriage returns
mixed, it is not validated.
Is tehre a way to ignore all carriage returns?
I am a RE newbie. Thanks.
| |
by: TheRain |
last post by:
Hi,
I am trying to append a carriage return to my string using the string
builder class, but when I do this the string ends up containing "13".
I tried this multiple ways like so
sb->Append('\r');
and also
|
by: Dinsdale |
last post by:
I have an xml file that is read into an object using serialization. One
of the objects has a string field called delimeter that I want to
contain a carriage return. Instead of trying to include the carriage
return, I used "\r" thinking that when it was read back into the object
it would be interpreted as a carriage return. Instead, I am getting the
string literal instead of the escape sequence. Does anybody have a
slick way of telling it...
|
by: evenlater |
last post by:
My db allows the user to send email via CDO. The body of the email is
determined in code. I have built an email form with To, CC and Subject
lines and a large text box for the body of the message so the user can
edit the default email message body before sending the message.
But when I populate the large text box (txtBody), I can't get it to
include the carriage returns. I've tried vbNewLine, vbCrLf, Chr(10)
and Chr(13). I've got the...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
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();...
|
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
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |