Line break ' \ n ' and carriage return ' \ R '
As the name suggests, the line break is another line, the carriage return is back to the beginning of a line, so we usually write the file returns should be called carriage return line character
' \ n ' (0x0a) line wrap (newline)
' \ R ' (0x0d) enter (return)
Can also be expressed as ' \x0a ' and ' \x0d '. (16 in-system)
Under Windows System, the carriage return line symbol is "\ r \ n". But there is no "\ r" symbol under Linux and other systems.
In parsing text or other formats of the content of the file, often to meet the decision to enter the line, this time to be aware of both "\ r \ n" and the decision "\ n".
When writing a program, you may get a line, trim it off ' \ R ', and get the string you need.
=============================================== "NOTE/master: xqzhang2015"
1. When writing a program, the code inside is ' \ n ' indicates a newline.
2. For wrapping in a file,
(1) In Windows system, the file at the end of each line is "< return >< change line >" "\ r \ n"
(2) in the Mac system, the file at the end of each line is "< return >", that is, ' \ R '
(3) Unix system, the end of each file line is "< newline >", that is, ' \ n '
So, with ' \ n ' as a newline, there will be no line breaks when you open Notepad with Windows;
with "\ r \ n" as a newline character file (Windows file), the Linux or Mac vim will be opened to display \ R as ^m.
In the Mac's zsh, with \ n as a newline, the encounter \ R will be interpreted as a carriage return, that is, move to the beginning of the line, and then continue executing the code.
With questions X-1:
"Replace the ^m with Vim in a Mac or Unix system with a normal line break"
Executes the. SH script in Linux, exception/bin/sh^m:bad interpreter:no such file or directory.
Analysis: This is the result of different system encoding formats: the. sh file edited in the Windows system may have invisible characters, so it will report the above exception information in the Linux system.
Solve:
1 conversion under Windows:
Use tools such as UltraEdit or editplus to convert scripts to code and then execute them in Linux. The conversion method is as follows (UltraEdit): File-->conversions-->dos->unix.
2) can also be converted in Linux:
First, make sure that the file has executable permissions #sh >chmod a+x filename
Then modify the file format #sh >vi filename
Use the following command to view the file format: Set FF or: Set FileFormat
You can see the following information Fileformat=dos or Fileformat=unix
use the following command to modify the file format : Set Ff=unix or: Set fileformat=unix{set Ff=unix "FileFormat"}
: Wq (Disk exit)
Finally execute the file #sh >./filename
What ' s meaning of "configure:error:cannot run/bin/sh config/config.sub"
When you weave a thing
Execution./configure the wrong time.
"Configure:error:cannot run/bin/sh config/config.sub"
The result is that the system does not have the edge of the Libtool, and then again./configure doesn't have a problem.
With questions X-2:
"How C + + removes \n,\r,\t, spaces at the end of a string string. "
#include <iostream>
#include <string>
using namespace std;
/* Delete string beginning/end of character/
int main (void)
{
string s = "\r\n\t is \ t This is a casually written word." \t\t ";
size_t n = s.find_last_not_of ("\r\n\t");
if (n!= string::npos)
{
s.erase (n + 1, s.size ()-n);
}
n = s.find_first_not_of ("\r\n\t");
if (n!= string::npos)
{
s.erase (0, N);
}
cout << s << endl;
}
➜ test g++ test.cpp
➜ test ./a.out
It's a random word.
Recommend a site to everyone: http://stackoverflow.com/
With questions X-3:
"Mac Vim handles DOS line breaks ^m"
Today, with Macvim open a colleague wrote a file, code into only one line, in the original line after more than ^m.
This is because the DOS line break is not supported on my side, so replace ^m for the Mac side line break,
In vim edit mode, enter:
:%s/^m/\r/g ^m obtained by ctrl+v+m
This will replace all ^m to wrap, then save the file ok