小编Fro*_*art的帖子

在C++中初始化构造函数初始化列表中的char数组

可以像这样使用初始化吗?

class Foo
{
public:
   Foo() : str("str") {}
   char str[4];
};
Run Code Online (Sandbox Code Playgroud)

还有这个?

int main()
{
   char str[4]("str");
}
Run Code Online (Sandbox Code Playgroud)

两者都给我gcc 4.7.2中的错误:

error:用作初始化程序的数组

Comeau编译两者.

c++ arrays class initialization-list

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

C和C++中的宏重新定义

我知道这段代码在C和C++中都是有效的:

#define FOO 0
#define FOO 0
Run Code Online (Sandbox Code Playgroud)

ISO/IEC 14882:2011

16.3宏替换[cpp.replace]

2当前定义为类似对象的宏的标识符可以由另一个#define预处理指令重新定义,前提是第二个定义是类似于对象的宏定义,并且两个替换列表相同,否则程序格式不正确.同样,当前定义为类似函数的宏的标识符可以由另一个#define预处理指令重新定义,前提是第二个定义是具有相同数量和参数拼写的类函数宏定义,并且两个替换列表相同,否则该计划是不正确的.

但是这段代码怎么样?

#define FOO 0
#define FOO FOO
Run Code Online (Sandbox Code Playgroud)

替换列表在预处理开始时不相同(仅在第一次替换发生时).

c c++

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

有效的标头名称

我无法正确理解以下文章中的含义:

\n\n

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1566.htm

\n\n
\n

有趣的是,C89 明确允许在标头和包含文件名中仅包含字母。C++ 添加了下划线,C99 添加了\n 数字。也许两个标准都应该允许两者。

\n
\n\n

我在所有 C 和 C++ 标准中发现了以下语句:

\n\n

ISO/IEC 9899:1990

\n\n
\n
6.1.7 Header names\n\nSyntax\n1 header-name:\n< h-char-sequence >\n" q-char-sequence "\nh-char-sequence:\nh-char\nh-char-sequence h-char\nh-char:\nany member of the source character set except\nthe new-line character and >\nq-char-sequence:\nq-char\nq-char-sequence q-char\nq-char:\nany member of the source character set except\nthe new-line character and "\n
Run Code Online (Sandbox Code Playgroud)\n
\n\n

ISO/IEC 9899:1990

\n\n
\n
5.2.1 Character sets\n\n...\n\nBoth the basic source and basic execution character sets shall have the following\nmembers: the 26 uppercase letters of …
Run Code Online (Sandbox Code Playgroud)

c c++

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

将std :: ios_base :: trunc标志与std :: ios_base :: out一起使用的目的是什么

使用std::ios_base::trunc标志的目的是什么std::ios_base::out?我在很多例子中都看过这个.

我认为标准std::ios_base::out也保证了截断文件(以及我知道的所有STL实现).我错了,应该明确通知我要截断文件?

c++

5
推荐指数
2
解决办法
2306
查看次数

如何在ASP.NET应用程序中使用SSL

我想在我的ASP.NET应用程序中使用SSL.我该怎么办?我在互联网上找到了许多教程,但遗憾的是,所有这些教程都不起作用(直到那时我从未使用过证书).

在ASP.NET应用程序中使用SSL的最简单方法是什么?我当然是在谈论自签名证书.

c# asp.net asp.net-mvc ssl ssl-certificate

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

提升精神队长 - 编译时错误

我有以下代码:

#include <boost/fusion/include/define_struct.hpp>
#include <boost/spirit/include/qi.hpp>

#include <iostream>
#include <string>

BOOST_FUSION_DEFINE_STRUCT(
  (), foo,
  (int, bar)
  (int, baz)
)

template <typename Iterator>
struct parser : boost::spirit::qi::grammar<Iterator, foo(), boost::spirit::qi::ascii::space_type>
{
  parser() : parser::base_type(start)
  {
    start %= boost::spirit::qi::int_ >> boost::spirit::qi::int_;
  }

  boost::spirit::qi::rule<Iterator, foo(), boost::spirit::qi::ascii::space_type> start;
};

int main()
{
  const std::string input_data("0 1");

  foo instance;
  auto itr = input_data.begin();
  auto end = input_data.end();
  parser<decltype(itr)> g;
  bool res = boost::spirit::qi::phrase_parse(
    itr
    , end
    , g
    , (
        boost::spirit::ascii::space
        | ("//" >> *(boost::spirit::qi::char_ - boost::spirit::qi::eol) >> …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-spirit boost-spirit-qi

5
推荐指数
2
解决办法
531
查看次数

C++ 11原子类和操作 - 我是对的

我在以下假设中是正确的:

  • 我不需要std::atomic<T>使用我自己的同步对象显式同步对任何平台上不同线程的对象的访问
  • std::atomic<T> 操作可以是无锁的,也可以是非锁定的,取决于平台
  • std::atomic_boolstd::atomic<bool>(和其他类似的)实际上是相同的东西
  • std::atomic_flag 是唯一保证标准独立于平台的无锁操作的类

另外,我在哪里可以找到有用的信息std::memory_order以及如何正确使用它?

c++ multithreading c++11

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

如何防止QDialog类关闭

如何在按下“确定”按钮后防止QDialog类关闭?只有在此对话框中正确执行了某些操作后,才需要关闭窗口,在其他情况下,则不需要关闭该窗口。

c++ qt qt-creator

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

Python 和 SSL——EOF 发生违反协议

我正在尝试通过 Python 登录该网站。我有以下代码:

import sys
sys.path.append('ClientCookie-1.3.0')
import ClientCookie
sys.path.append('ClientForm-0.2.10')
import ClientForm

cookieJar = ClientCookie.CookieJar()

opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(cookieJar))
opener.addheaders = [("User-agent","Mozilla/5.0 (compatible)")]
ClientCookie.install_opener(opener)
fp = ClientCookie.urlopen("login_page_url")
forms = ClientForm.ParseResponse(fp)
fp.close()

# print forms on this page
for form in forms: 
    print("***************************")
    print(form)

form = forms[2]
form["username"] = "some_username"
form["password"] = "some_password"
fp = ClientCookie.urlopen(form.click())
fp.close()
fp = ClientCookie.urlopen("some_url_for_authorized_users_only")
html = fp.read()
fp.close();
print(html.decode('utf-8'))
Run Code Online (Sandbox Code Playgroud)

输出

URLError: <urlopen error [Errno 8] _ssl.c:507: EOF occurred in violation of protocol>
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?这是什么意思?我该如何修复这个错误?

python authentication cookies ssl http

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

如果isAvailableForServiceType方法返回NO,我该怎么办?

isAvailableForServiceType例如,如果方法在Twitter的情况下返回NO,我该怎么办?

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
    // post message
} else {
    // show some additional screen
}
Run Code Online (Sandbox Code Playgroud)

我可以以某种方式为用户提供标准的登录/注册视图或将他切换到iOS设置吗?如果是,我该怎么办?

提前致谢.

cocoa-touch objective-c ios

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