我观察到以下情况:
>>> print '£' + '1'
£1
>>> print '£' + u'1'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128)
>>> print u'£' + u'1'
£1
>>> print u'£' + '1'
£1
Run Code Online (Sandbox Code Playgroud)
为什么'£' + '1'工作但'£' + u'1'不起作用?
我查看了类型:
>>> type('£' + '1')
<type 'str'>
>>> type('£' + u'1')
Traceback (most recent call last):
File "<stdin>", line 1, in <module> …Run Code Online (Sandbox Code Playgroud) 这是代码:
class cat
{
private:
int height;
public:
cat (int inputHeight);
};
cat::cat (int inputHeight)
{
height = inputHeight;
}
class twoCats
{
private:
cat firstCat;
cat secondCat;
public:
twoCats (cat theFirstCat);
void addSecondCat (cat theSecondCat);
};
twoCats::twoCats (cat theFirstCat)
{
firstCat = theFirstCat;
}
void twoCats::addSecondCat (cat theSecondCat)
{
secondCat = theSecondCat;
}
int main() {return 0;}
Run Code Online (Sandbox Code Playgroud)
这些是错误:
main.cpp: In constructor ‘twoCats::twoCats(cat)’:
main.cpp:24:34: error: no matching function for call to ‘cat::cat()’
main.cpp:24:34: note: candidates are:
main.cpp:9:1: note: cat::cat(int)
main.cpp:9:1: …Run Code Online (Sandbox Code Playgroud) 在文件中输入:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Hello
A
Hello
B
Run Code Online (Sandbox Code Playgroud)
然后使用/以下方法搜索:
\(Hello\n\)\@<=A
Run Code Online (Sandbox Code Playgroud)
在我的Vim版本(7.4,包含的补丁:1-582)中,A底部Hello按预期匹配,B不是,但A第一行的第446位匹配.
这也有一些奇怪的行为,如果我用更多的As 做更长的线,632nd A会突出显示.如果我在行的开头引入16个空格,则该行上的第447个和第632个字符匹配.
我的问题是,这是否会影响其他人,这是一个真正的错误还是我的搜索错误?
如果我在类构造函数中使用malloc(或new/ new[])分配内存,那么该内存是否可以被覆盖?
class stack {
private:
int * stackPointer;
public:
stack (int size) {
stackPointer = (int *) malloc (sizeof(int) * stackSize);
}
int peek (int pos) {
return *(stackPointer + pos); //pos < size
}
}
Run Code Online (Sandbox Code Playgroud) echo "$(expr "title: Purple Haze artist: Jimi Hendrix" : 'title:\s*\(.*\?\)\s*artist.*' )"
Run Code Online (Sandbox Code Playgroud)
版画
Purple Haze
Run Code Online (Sandbox Code Playgroud)
使用尾随空格,即使我使用的是?懒惰运算符.
我在https://regex101.com/上测试了这个,它按预期工作,bash有什么不同?