请帮我使用sed.我有一个如下文件.
START=A
xxxxx
xxxxx
END
START=A
xxxxx
xxxxx
END
START=A
xxxxx
xxxxx
END
START=B
xxxxx
xxxxx
END
START=A
xxxxx
xxxxx
END
START=C
xxxxx
xxxxx
END
START=A
xxxxx
xxxxx
END
START=D
xxxxx
xxxxx
END
Run Code Online (Sandbox Code Playgroud)
我想在START = A,END之间得到文本.我使用了以下查询.
sed '/^START=A/, / ^END/!d' input_file
Run Code Online (Sandbox Code Playgroud)
这里的问题是,我得到了
START=A
xxxxx
xxxxx
END
START=D
xxxxx
xxxxx
END
Run Code Online (Sandbox Code Playgroud)
代替
START=A
xxxxx
xxxxx
END
Run Code Online (Sandbox Code Playgroud)
塞德贪婪地发现.
请帮我解决这个问题.
提前致谢.
我可以使用AWK实现上述目标吗?
函数重载可能发生在具有相同参数数量的两个成员函数之间,如果其中一个成员函数声明为const.
但是如果一个函数有一个const参数,另一个函数具有相同类型的非const参数呢?它适用于引用和指针吗?如果C++提供它,它为什么提供?如果你知道,请与我分享原因.
以下是帮助您理解上述场景的示例.
void fun(const int i)
{
cout << "fun(const int) called ";
}
void fun(int i)
{
cout << "fun(int ) called " ;
}
int main()
{
const int i = 10;
fun(i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:编译器错误: redefinition of 'void fun(int)'
void fun(char *a)
{
cout<<"non-const fun() called";
}
void fun(const char *a)
{
cout<<"const fun() called";
}
int main()
{
const char *ptr = "GeeksforGeeks";
fun(ptr);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:const fun()调用
为什么在C++中允许第二个?
请告诉我为什么以下程序的输出如下.我没有在c ++中获得虚拟类.请遵守以下代码:
class B
{
public:
B(char c = 'a') : m_c(c) {}
public:
char get_c() const { return m_c; }
void set_c(char c) { m_c = c; }
private:
char m_c;
};
class C: public B
{ };
class D: public B
{ };
class E
: public C
, public D
{ };
int main()
{
E e;
C &c = e;
D &d = e;
std::cout << c.get_c();
d.set_c('b');
std::cout << c.get_c() << std::endl;
return 0;
} …Run Code Online (Sandbox Code Playgroud) 我想有 C++ 应用程序编程的工作经验。我两难选择游戏编程还是单机编程。请建议我学习哪个框架/API 对我有益。
Qt mobile / QT gui编程,任何其他API,学习MFC而不是QT怎么样,除了qt还有其他gui框架吗?
请遵守以下代码.据我所知,dynamic_cast比static_cast慢.因为它在运行时评估类型.我在这里的疑问是,如果我们将static_cast与typeid()一起使用如下,它是否需要与动态强制转换相同的时间?它会比dynamic_cast快吗?
class Shape
{
public:
virtual ~Shape(){}
};
class Circle : public Shape{ };
class Square : public Shape{ };
Run Code Online (Sandbox Code Playgroud)
使用RTTI进行静态转换:
Circle c;
Shape* s = &c; // Upcast: normal and OK
// More explicit but unnecessary:
s = static_cast<Shape*>(&c);
// (Since upcasting is such a safe and common
// operation, the cast becomes cluttering)
Circle* cp = 0;
Square* sp = 0;
// Static Navigation of class hierarchies
// requires extra type information:
if(typeid(s) == typeid(cp)) // C++ RTTI …Run Code Online (Sandbox Code Playgroud) class A
{
};
class B:public A
{
};
int main()
{
A a;
B b;
A *ap = &b;
B *bp = dynamic_cast<B*>(ap);
if(bp!= NULL)
cout<<"Pass"<<endl;
else
cout<<"Fail"<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果你想进行动态演员,为什么A类应该是虚拟的呢?
请尝试编写rand30()应返回1到30的函数.
你有rand100()功能.
c++ ×5
dynamic-cast ×2
virtual ×2
algorithm ×1
awk ×1
const ×1
overloading ×1
polymorphism ×1
qt ×1
regex ×1
sed ×1
shell ×1
static-cast ×1