在Linux 3.0/C++下:
我想要一个执行以下操作的函数:
string f(string s)
{
string r = system("foo < s");
return r;
}
Run Code Online (Sandbox Code Playgroud)
显然上面的方法不起作用,但你明白了.我有一个字符串s,我想传递作为应用程序"foo"的子进程执行的标准输入,然后我想将其标准输出记录到字符串r然后返回它.
我应该使用linux系统调用或posix函数的组合?
我正在尝试使用BFD库,所以我已经安装了包binutils-dev并且包括:
#include <bfd.h>
Run Code Online (Sandbox Code Playgroud)
和我打电话bfd_openr,并bfd_close从我的代码等等.
最近我升级了包,现在我从这里得到一个错误:
bfd.h:
/* PR 14072: Ensure that config.h is included first. */
#if !defined PACKAGE && !defined PACKAGE_VERSION
#error config.h must be included before this header
#endif
Run Code Online (Sandbox Code Playgroud)
......我应该包括config.h- 但我没有使用autoconf.
我是否包含错误的头文件?你怎么用binutils-dev?
这是一个演示程序:
#include <stdio.h>
#include <bfd.h>
int main()
{
bfd_init();
bfd* file = bfd_openr("a.out", 0);
if (!file)
return -1;
if (bfd_check_format(file, bfd_object))
printf("object file\n");
else
printf("not object file\n");
bfd_close(file);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
尝试编译并运行如下:
$ sudo apt-get install binutils-dev
$ …Run Code Online (Sandbox Code Playgroud) 假设我在父窗口小部件内的垂直布局中有两个Qt小部件.
有没有办法在它们之间添加一个控件"边框",这样当你在两个宽边之间单击并拖动边框区域时,你可以改变它们所采用的父级的相对区域?
也就是说,如果将其向上拖动,则底部窗口小部件的大小调整得更大,顶部窗口小部件的调整大小更小.
任何想法为什么virtual~exception()throw()在C++ 98中,但virtual~exception()在C++ 11中?
什么是允许C++ 11投入类的析构函数的设计决策exception?
从这里:
C++ 98:
class exception {
public:
exception () throw();
exception (const exception&) throw();
exception& operator= (const exception&) throw();
virtual ~exception() throw();
virtual const char* what() const throw();
}
Run Code Online (Sandbox Code Playgroud)
C++ 11:
class exception {
public:
exception () noexcept;
exception (const exception&) noexcept;
exception& operator= (const exception&) noexcept;
virtual ~exception();
virtual const char* what() const noexcept;
}
Run Code Online (Sandbox Code Playgroud) 这个C++ 11程序是否格式错误?
typedef void& rv;
int main() {}
Run Code Online (Sandbox Code Playgroud)
我在标准中找不到任何禁止它的东西(见3.9.2和8.3.2).
Clang说"不能形成对'void'的引用",gcc说"不能声明引用'void'"
如果有意的话,我本来期望[dcl.ref]/5给出这样的限制.
实现只是"在行之间读取",因为这种类型永远不能在对象定义中使用吗?
在C++ 11中经常需要定义一个以容器作为参数的函数.
例如,让我们定义一个函数addup(是的只是一个简单的版本std::accumulate):
template <class I>
int addup (I first, I last)
{
int x = 0;
while ( first != last )
x += *first++;
return x;
}
Run Code Online (Sandbox Code Playgroud)
这需要一个迭代器范围,这是灵活的标准库惯用法.
但是假设我有一个功能:
vector<T> f();
Run Code Online (Sandbox Code Playgroud)
我必须这样做:
auto v = f();
int x = addup(v.begin(), v.end());
Run Code Online (Sandbox Code Playgroud)
我宁愿这样做:
int x = addup(f());
Run Code Online (Sandbox Code Playgroud)
就像我可以这样做:
for (auto t : f())
...
Run Code Online (Sandbox Code Playgroud)
本着基于范围的精神,我想要这样的事情:
template<class C>
int addup(C&& container)
{
addup(beginexpr(container), endexpr(container)); // ???
}
Run Code Online (Sandbox Code Playgroud)
在标准中它在6.5.4(释义)中说:
(A)if
container是数组类型,beginexpr并且endexpr …
在C++ 11 N3485 5.3.5.1中它说:
操作数[of
delete]应该是指向对象类型或类类型的指针.如果是类类型,则操作数在上下文中转换为指向对象类型的指针.
这种用法的例子是什么(操作数是类类型的)?
在C++ 11和/或C++中:
假设我给出了一个带有非类型参数包的模板:
template<int...>
void f();
Run Code Online (Sandbox Code Playgroud)
我正在编写另一个将实例化它的模板:
template<int... x>
void g()
{
???
f<???>();
}
Run Code Online (Sandbox Code Playgroud)
我希望g以排序顺序用x实例化f.
那是:
g<4,7,2,9,3,7>();
Run Code Online (Sandbox Code Playgroud)
应致电:
f<2,3,4,7,7,9>();
Run Code Online (Sandbox Code Playgroud)
可以这样做吗?如果是这样,最有效的方法是什么(由常数因素决定)?
如果我有一个静态局部变量或thread_local局部变量,它在一个内联函数中,在不同的翻译单元中定义,在最终的程序中它们是否由标准保证具有相同的地址?
// TU1:
inline int* f() { static int x; return &x; }
extern int* a;
void sa() { a = f(); }
// TU2:
inline int* f() { static int x; return &x; }
extern int* b;
void sb() { b = f(); }
// TU3:
int *a, *b;
void sa();
void sb();
int main() { sa(); sb(); return a == b; }
Run Code Online (Sandbox Code Playgroud)
以上总是会返回1吗?
假设我有一个这样的类模板:
template<typename T, size_t N>
struct S {
std::array<T,N> a;
};
Run Code Online (Sandbox Code Playgroud)
是否有我可以放置的默认成员初始化程序a,
template<typename T, size_t N>
struct S {
std::array<T,N> a = ???;
};
Run Code Online (Sandbox Code Playgroud)
这样,无论是什么T,都a将永远初始化元素(永远不会有不确定的价值)?即,即使T是原始类型int.