Remove blank line in c++ [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
How to remover blank lines after reading a text file using c++?
while(arry[i]="/n"){
i++;
}
This is my code.It gives some output.But it is not a expected output.

while (arry[i] == '\r' || arry[i] == '\n') {
i++;
}
And please add the checkpoint of the boundary of arry like that:
i < arry.length()
\r is a carriage return character; it tells your terminal emulator to move the cursor at the start of the line. So, \r allows to override the current line of the terminal emulator.
In C++ single quotes identify a single character, while double quotes create a string literal. 'a' is a single a character literal, while "a" is a string literal containing an 'a' and a null terminator

Related

I cannot read spaces and enters in c++ using devc++ [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Hi I am new here and I have little problem I guess. I want my program to change one character in whole text in text file. For example I want to change all A to G. But when I read it ,it does not even read spaces and enters. Also I want to write eddited text in new textfile. Thanks for help.
At the beginning you should load whole file.
std::ifstream is("file.txt");
is >> std::noskipws;
std::istream_iterator<char> start(is), end;
std::vector<char> buffer(start, end);
is >> std::noskipws prevents stream from skipping white characters like space or enter. Then replace characters using std::replace(buffer.begin(), buffer.end(), 'A', 'G');.
Now simply save file:
std::ofstream out("file.txt", std::ofstream::binary);
std::copy(buffer.begin(), buffer.end(), std::ostreambuf_iterator<char>(out));
You may want to read something about those:
std::ostreambuf_iterator, std::istream_iterator, std::noskipws, std::replace.

How can i get all the text until a space don't come in Qstring? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Hello i want to get the ultil the space in line occur for example
in the given picture am able to get the whole string using getter method to my parent window but i dont want get the date time part
am currently getting
https://www.youtube.com/watch?v=VXw6OdVmMpw Sun Nov 1 20:29:30 2015
while i want get https://www.youtube.com/watch?v=VXw6OdVmMpw
can anyone help me i used Qstring left right but i cant get it working properly.
//QString Input holds your data...
QString Output = Input.section(' ', 0, 0);
section sees the string as fields seperated by a seperator character (' ' in this case) and returns the section from the given start section (0) upto and including the end section (0).
Assuming the white space in your inputstring is really spaces, if it is not, change ' ' to the correct seperator character.

Replacing ascii with matching characters using perl / awk or other [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have an access log that was written with nginx and lua code.
It is url encoded and those some characters are written in the format of \xHexCode (for example, double quotes are written as \x22).
I would like to run awk or perl or other fast script to replace it back.
You can use gnu-awk like this:
str='\x22 \x41 written as \x22).'
awk -v RS='\\\\x[0-9]+' 'RT{ORS=sprintf("%c", strtonum("0" substr(RT, 2)))} 1' <<< "$str"
" A written as ").
This is how it is working:
Using RS='\\\\x[0-9]+' we're separating custom record separator for each of those \xNN numbers.
substr(RT, 2) takes x41 from \x41
strtonum("0" substr(RT, 2)) adds 0 to make it 0x41 and returns ascii code 65.
printf "%c" prints equivalent ascii character A from 65.
ORS=... sets output record separator same as the return value of sprintf.

Can not open a text file with the " fstream " [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
My current difficulties will open "My File.txt" using fstream.
in "My File.txt" there is a long sentence. so I use the AnsiString to accommodate the text that is inside
void __fastcall TFormManager::Button1Click(TObject *Sender) {
AnsiString FileName, tmpText;
FileName = "\conf\db\My Text.txt";
if (FileExists(FileName)) {
ifstream data(FileName);
data >> tmpText;
}
}
i use C++ Builder XE6. Thx
Double the backslashes:
FileName = "\\conf\\db\\My Text.txt";
Sometimes you need to put a symbol in a string literal that has no equivalent in the keyboard or that can not be accepted directly in the source code. For example, if you need to add a line break in a string, many languages require you to use an equivalent escape sequence.
In C/C++, escape sequences are started by a single \. So for example:
\n = Enter
\t = Tab
If you want to use a single \ in your string literal, you must escape it as \\.
http://en.wikipedia.org/wiki/Escape_sequences_in_C
In many systems, you can use / to separate your path.

C++ \n in a string (Not working) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I'm learning C++. Here's my problem.
http://prntscr.com/2m5flm
I created a function who can read Prop files like them (you can set the file beginning and ending tags with a function, searching a specified tag with a function who will return a string (containing the results).
Here's the main.cpp
#include <iostream>
#include "m_PFile_r.h"
using namespace std;
int main(int argc, const char * argv[])
{
m_PFile_r k;
k.open("prop.arg");
k.imNotaFag(true);
k.setOpenArg("$FILE_BEGIN$");
k.setCloseArg("$FILE_END$");
string lS;
lS=k.getArg("launchSentence");
cout << lS << endl;
string menu;
menu=k.getArg("progMenu");
cout << menu;
return 0;
}
MY QUESTION IS : Why doesn't it print the \n as a line return ?
Thanks :)
The file has new line characters in it, they are defining the end of the lines. When you enter the newline character in the file, it is being stored in that file not as a newline character, but the two individual characters "\" and "n". So when you then read in the file, those characters are read in just like the others.
You are over complicating this problem. If you would like to print out various phrases to the user, just include those phrases as string variables in your program.
String launchSentence = "This is the launch sentence.";
String progMenu = "Hit 1 For Add Hit 2 for Subtract";
These could then be printed with the normal COUT << progMenu method.
If your purpose with the text file is to keep all of the possible text strings isolated in one easy location, why not create a TextCommandPrompts.h, fill it with the String (character in C++) variables and include that in your main?
Edit - Because I can't comment yet and I want to respond to one - I thought that whatever text editor that was letting him write line by line would be messing this up. As in, its already doing the "\n" magic, and when he writes in the characters '\' and 'n' something mundane happened, and they stayed as regular characters.