小编Tom*_*mmy的帖子

C++ 命名空间未声明但已声明?

我有一个编译时间问题。刚接触 C++,所以我相信这很简单。我得到了当前的错误。

diarydb.cpp: In function ‘bool editdate(int, mysqlpp::Connection&)’: diarydb.cpp:413:
error: ‘format_tests’ has not been declared
Run Code Online (Sandbox Code Playgroud)

但是 diardby.cpp 我在这里声明了 format_tests

namespace format_tests {
  bool testdateformat(string &date);
  bool tesettimeformat(string &time);
  bool lengthcheck(string &in,int length);

}
Run Code Online (Sandbox Code Playgroud)

bool format_tests::testdateformat(string &date){
  // tests format of dat input for MYSQL form at of YYYY-MM-DD
  // Need to tweak regex to restrict 0 < MM < 12 and 0 < DD <31.

  const boost::regex e("\\d{4}\\x2D\\d{2}\\x2D\\d{2}");
  return boost::regex_match(date,e);
}
Run Code Online (Sandbox Code Playgroud)

此处调用的编译器编译器。

  bool dbsetget::editdate(int e_id,mysqlpp::Connection &con){

        char evdate[11];

    cout …
Run Code Online (Sandbox Code Playgroud)

c++ namespaces

6
推荐指数
1
解决办法
2万
查看次数

线程成本

我了解如何用我选择的语言创建线程,也了解互斥锁,以及共享数据的危险等,但是我对操作系统将如何管理线程以及每个线程的成本有所把握。我遇到了所有相关的严重问题,而表达我的理解极限的最清晰方法可能就是通过这些问题。

产生线程的成本是多少?设计软件时是否值得担心?创建线程的成本之一必须是其自己的堆栈指针和进程计数器,然后是在调度程序将其移入或移出内核时将所有工作寄存器复制到的空间,但是还有什么呢?

是可用于一个程序的堆栈数量在进程的线程之间平均分配,还是先到先得?

我能以某种方式检查启动时(程序的)硬件的内核数量。如果我在具有N个内核的计算机上运行,​​是否应该将线程数保持为N-1?

resources multithreading operating-system

6
推荐指数
1
解决办法
1104
查看次数

将boost :: posix_time :: time_duration提升为字符串

您好我正在使用boost Posix Time System.我上课了

class event{
private:
boost::posix_time::ptime time;

//some other stuufff

public:
string gettime(void);
}

//functions
string event::gettime(void){
return  to_iso_extended_string(time.time_of_day());
}
Run Code Online (Sandbox Code Playgroud)

但是to_iso_extended_string不接受类型

boost::posix_time::time_duration
Run Code Online (Sandbox Code Playgroud)

只有类型

boost::posix_time
Run Code Online (Sandbox Code Playgroud)

这可以在这里看到

我想返回一个字符串以供以后输出等

我怎么解决这个问题?我无法在boost中看到转换方法

boost::posix_time::time_duration
Run Code Online (Sandbox Code Playgroud)

串起来.我是C++的新手,如果这是一个非常简单的话,我会道歉.

c++ boost

3
推荐指数
2
解决办法
9447
查看次数

了解getopt()示例.int与char的比较

大家好,我希望你能帮助我理解为什么getopt使用了int并在getopt中处理了optopt变量.对C++来说很陌生.

看看getopt,optopt被定义为一个整数. http://www.gnu.org/software/libtool/manual/libc/Using-Getopt.html#Using-Getopt

和这里的例子, http://www.gnu.org/software/libtool/manual/libc/Example-of-Getopt.html#Example-of-Getopt

在这个例子中,我不理解的部分是如何将`c',一个整数与switch语句中的char进行比较.

据我所知,geopt的主要参数是字符数组argv,因此它处理返回int的事实对我来说似乎很奇怪,我的期望是char,我需要将任何数字参数转换为int.char是自动转换为它的ANSI代码又回来了吗?printf语句

fprintf (stderr, "Unknown option `-%c'.\n", optopt);
Run Code Online (Sandbox Code Playgroud)

正如我所理解的那样期待一个char,但是给了一个int.为什么getopt在处理字符数组时会使用int?

我错过了一些非常明显的东西吗 我必须.

c c++ integer-promotion

1
推荐指数
1
解决办法
2106
查看次数