我需要一个正则表达式来捕获括号之间的参数.不应该捕获论证之前和之后的空白.例如,"( ab & c )"应该返回"ab & c".如果需要前导或尾随空白,则可以将参数括在单引号中.所以,"( ' ab & c ' )"应该回来" ab & c ".
wstring String = L"( ' ab & c ' )";
wsmatch Matches;
regex_match( String, Matches, wregex(L"\\(\\s*(?:'(.+)'|(.+?))\\s*\\)") );
wcout << L"<" + Matches[1].str() + L"> " + L"<" + Matches[2].str() + L">" + L"\n";
// Results in "<> < ' ab & c '>", not OK
Run Code Online (Sandbox Code Playgroud)
似乎第二种选择匹配,但它也占据了第一个引用前面的空间!应该\s在开括号之后抓住它.
删除第二个替代方案:
regex_match( String, Matches, wregex(L"\\(\\s*(?:'(.+)')\\s*\\)") );
wcout …Run Code Online (Sandbox Code Playgroud) 我想向图形场景添加一个简单的文本项(一个字),因此使用 QGraphicsSimpleTextItem。文本项的场景坐标定义了文本的左上角。
是否可以让文本中心围绕坐标对齐?
考虑这个课程:
#include <vector>
using namespace std;
template<typename T>
class Vector{
private:
size_t size_;
vector<T> items;
public:
Vector(){ size_ = 0; }
inline void clear(){ size_ = 0; }
inline void push_back( const T item ){
if( items.size() == size_ )
items.push_back( item );
else
items[size_] = item;
size_++;
}
inline const T& operator[](int i) const { return items[i]; }
inline T& operator[](int i) { return items[i]; }
};
int main(int argc, char *argv[]){
Vector<bool> vec;
vec.push_back( true );
if( vec[0] …Run Code Online (Sandbox Code Playgroud) 考虑以下代码:
struct TNumeric {
bool Negative;
wstring Integral;
wstring Fraction;
};
union TValue {
// The unnamed structs are needed because otherwise the compiler does not accept it...
bool Bit;
struct{ TNumeric Numeric; };
struct{ wstring Text; };
};
TNumeric Numeric;
TNumeric &rNumeric{ Numeric };
rNumeric.Integral = L"";
rNumeric.Integral.push_back( L'X' ); //OK, no problem
TValue Value;
TValue &rValue{ Value };
rValue.Text = L"";
rValue.Text.push_back( L'X' ); //OK, no problem
rValue.Numeric.Integral = L"";
rValue.Numeric.Integral.push_back( L'X' ); // Exception
Run Code Online (Sandbox Code Playgroud)
在发布模式下没有问题.在调试模式下运行时,xutility中类_Iterator_base12的方法_Adopt中的最后一个语句有一个异常:Access violation …