我想挑起一个没有文件描述符的情况.
我一直在考虑两种可能性:
你会怎么做?
通过升级C库解决了该问题.
我想使用syscall getrandom(http://man7.org/linux/man-pages/man2/getrandom.2.html)
gcc-5 -std = c11 test.c
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <linux/random.h>
#include <sys/syscall.h>
int main(void)
{
void *buf = NULL;
size_t l = 5;
unsigned int o = 1;
int r = syscall(SYS_getrandom, buf, l, o);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
要么
int main(void)
{
void *buf = NULL;
size_t l = 5;
unsigned int o = 1;
int r = getrandom(buf, l, o);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
无论如何,当我尝试用gcc-5编译它时:
test.c: …Run Code Online (Sandbox Code Playgroud) 我对C很新.
#include <string.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
char* c=argv[1];
for (int i=0;i<sizeof(c);i++)
{
printf("%c\n",c[i]);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试编写一个程序来打印单词的每个字符.
当我尝试测试时:它显示当我尝试使用testtesttest时:显示:t e s t
我不明白为什么,你能告诉我为什么好吗?
我试图操纵迭代器.
template <typename Mytype>
class Myclass
{
public:
Myclass ( const Mytype & myarg)
{
this->data=myarg;
}
~Myclass ( void ){}
set<int> Test ( const Mytype & myarg ) const
{
set<int> result;
typename Mytype::iterator it=myarg.begin();
return result;
}
private:
//
mutable Mytype data;
};
Run Code Online (Sandbox Code Playgroud)
这段代码正在编译.但是当我想使用它时,它不再编译:这是一个例子:
int main()
{
Myclass <string> t0 ( "caacaa" );
set<int> r=t0.Test("a");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我现在得到一个错误:
test.cpp: In member function ‘std::set<int> Myclass<Mytype>::Test(const Mytype&) const [with Mytype = std::basic_string<char>]’: test.cpp:38:26: instantiated from here test.cpp:25:48: …
我试图用模板解决一个练习.我的代码在大多数情况下运行良好,但我发现有一个案例无效,这是我的代码的一部分.默认比较器是<.
template <typename type1, typename typecomparator=less<typename type1::valuetype1> >
class Myclass
{
public:
Myclass ( const type1 & arg1,const typecomparator & comparator = typecomparator () )
{
this->seq=arg1;
this->comp=comparator;
}
~Myclass ( void ){}
// ...
private:
mutable type1 seq;
typecomparator comp;
};
Run Code Online (Sandbox Code Playgroud)
代码工作几乎是所有情况.为例:Myclass <string> test ( "abcabcabc" );
但是当我想要使用一个类时:
class another
{
public:
another ( bool caseSensitive )
: m_CaseSensitive ( caseSensitive ) { }
bool operator () ( const string & a, const string & b ) const …Run Code Online (Sandbox Code Playgroud)