How Do You Make New Lines In Text Files? Just A Quick Question In Need Of A Quick Answer. Keep In Mind That The Character(s) That Are Needed Have To Be Stored In A String Variable.
Thank You.
-Parker Woods
15 2718
"\n" is not working ???????
"\n" is not working ???????
Here is the code that is being used: - ...
-
string myString;
-
string text;
-
if (text == "\n")
-
{
-
myString = myString + "\n"
-
}
-
...
-
After that, it just goes on putting it into the text file as one big string. I know that works because every part of the string gets put in up until the new line.
Here is the code that is being used: - ...
-
string myString;
-
string text;
-
if (text == "\n")
-
{
-
myString = myString + "\n"
-
}
-
...
-
After that, it just goes on putting it into the text file as one big string. I know that works because every part of the string gets put in up until the new line.
It just occured to me...When you are getting input from a text file, does it read the "\n", or is it discarded? Hmmm...
-
string myString;
-
string text;
-
if (text == "\n")
-
{
-
myString = myString + "\n"
-
}
-
Hmm, let me think now... -
string myString;
-
string text;
-
if (text == "\n")
-
{
-
myString = myString
-
std::cout << "\n"
-
}
-
That should work.
-
string myString;
-
string text;
-
if (text == "\n")
-
{
-
myString = myString + "\n"
-
}
-
Hmm, let me think now... -
string myString;
-
string text;
-
if (text == "\n")
-
{
-
myString = myString
-
std::cout << "\n"
-
}
-
That should work.
Nope, that dosn't work.
Please remember that the newline has to be in a string and that string will be put into a text file.
DeMan 1,806
Top Contributor
Where are you getting "text" from (I realise the declaration is immediately before the if here just to highlight how it was declared), but I wondered whether you can post where you give text a value
Where are you getting "text" from (I realise the declaration is immediately before the if here just to highlight how it was declared), but I wondered whether you can post where you give text a value
I'm getting text from another text file. You see, I'm makeing a decrypter and the encrypter actualy gives every new line a numarical value, so thats whats happening.
DeMan 1,806
Top Contributor
Sorry, what I meant is what is the command you are using to fill the variable "text".
In the example you declare it and immediately test it (without assigning it a value). I understand this is for demonstration purposes, but how are you reading a value into "text" in your program.....
Assuming you read it line by line using getline, then you don't even need to test for "\n", simply add a "\n" after every call to getline().
Sorry, what I meant is what is the command you are using to fill the variable "text".
In the example you declare it and immediately test it (without assigning it a value). I understand this is for demonstration purposes, but how are you reading a value into "text" in your program.....
Assuming you read it line by line using getline, then you don't even need to test for "\n", simply add a "\n" after every call to getline().
Oh, sorry for the misunderstandin g. Well here is what I'm using: -
string fileOpen;
-
cin >> fileOpen; //The Path Of The File To Be Opened
-
ifstream fileopen;
-
fileopen.open(fileOpen.c_str());
-
if (fileopen.is_open())
-
{
-
while (! fileopen.eof() )
-
{
-
getline (fileopen,line);
-
text = text + line;
-
}
-
fileopen.close();
-
}
-
else
-
{
-
cout << "The File Was Unable To Open For An Unknown Reason. Please Check The Name" << endl;
-
cout << "You Gave The File And Try Again." << endl;
-
cout << " Program Terminated" << endl;
-
system("PAUSE");
-
return 0;
-
}
That is what I'm using to fill in " text".
But I will try to do that, you know, just add a " \n"
--Parker Woods
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: nic977 |
last post by:
I am asked to write a simple program to displays the last n lines from a
given text file. But I have no ideas how C defines a "line" in a text
file. How does it tell if it is the end of the line, is there such thing
call EOL like the EOF?
--
Posted via http://dbforums.com
|
by: a |
last post by:
I'm trying to remove specific lines from text files.
I need to always remove lines 1 thru 8 and lines 10 and 11 from text files.
Seems like a simple task, but I'm not getting it.
I'm reading the file via webresponse as a stream and then trying to remove
the lines before parsing it and then writing it to an sql table.
Any ideas on how I can accomplish the line removal/deletion?
|
by: davetelling |
last post by:
I am not a programmer, I'm an engineer trying to make an interface to a
product I'm designing. I have used C# to make a form that interrogates the
unit via the serial port and receives the data. I want to be able to draw
lines in a picturebox based upon certain data points I have received. I
dragged a picturebox from the toolbar onto my form, but after having gone
through the help files, looking online and trying a variety of things, I...
|
by: Justin Fancy |
last post by:
Hi everyone,
I need some help. I'm placing text files into a created database using
vb.Net. The problem is that, i need two seperate sql statements to add
both files because they are in different loops. My output comes out to
be as Follows:
TABLE
----------------------------------------------------
Field1 Field2
|
by: mellyshum123 |
last post by:
I need to read in a comma separated file, and for this I was going to
use fgets. I was reading about it at http://www.cplusplus.com/ref/ and
I noticed that the document said:
"Reads characters from stream and stores them in string until (num -1)
characters have been read or a newline or EOF character is reached,
whichever comes first."
My question is that if it stops at a new line character (LF?) then how
does one read a file with...
| |
by: ivan.perak |
last post by:
Hello,
im a beginner in VB.NET... The thing i would like to do is as it
follows....
I have a text file (list of names, every name to the next line) which
is about 350000 lines long. I would like to split it and create a new
file at every lets say 20000 lines... so, the directory output would
have to be something like this:
|
by: peraklo |
last post by:
Hello,
there is another problem i am facing. i have a text file which is
about 15000 lines big. i have to cut the last 27 lines from that file
and create a new text file that contans those 27 lines. and after that
save both of those files... since that is a big block of text (15000
lines) i thint that it is a big job to look for a keyword... so my
question is this exactly:
how do i do this:
|
by: ckirchho |
last post by:
Hallo,
my task is to establish some kind of full text file search in
Javascript. The files and it's contents are fixed, the HTML/JavaScript
pages lie offline on a server.
As far as Javascript cannot access files via any i/o operations, I
have written a routine in Delphi. It parses files in one folder and
generates a Javascrip tfile. The first lines build up a file table,
then the word index is build.
|
by: NvrBst |
last post by:
Whats the best way to count the lines? I'm using the following code
at the moment:
public long GetNumberOfLines(string fileName) {
int buffSize = 65536;
int streamSize = 65536;
long numOfLines = 0;
byte bArr = new byte;
|
by: rka77 |
last post by:
Hi,
I am trying to make a Python2.6 script on a Win32 that will read all the text files stored in a directory and print only the lines containing actual data. A sample file -
Set : 1
Date: 10212009
12 34 56
25 67 90
End Set
********
Set: 2
Date: 10222009
|
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: 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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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,...
|
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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |