Tag: C#的

我如何使用initializer_list初始化成员数组?

我正在加快C ++ 0x的速度,并用g ++ 4.6进行testing 我只是尝试下面的代码,认为它会工作,但它不会编译。 我得到的错误: incompatible types in assignment of 'std::initializer_list<const int>' to 'const int [2]' struct Foo { int const data[2]; Foo(std::initializer_list<int const>& ini) : data(ini) {} }; Foo f = {1,3};

为什么不std :: fstream类需要一个std :: string?

这不是一个devise问题,虽然它可能看起来像。 (好吧,这是一个devise问题)。 我想知道的是为什么C ++ std::fstream类不在构造函数或打开方法中使用std::string 。 每个人都喜欢这样的代码示例: #include <iostream> #include <fstream> #include <string> int main() { std::string filename = "testfile"; std::ifstream fin; fin.open(filename.c_str()); // Works just fine. fin.close(); //fin.open(filename); // Error: no such method. //fin.close(); } 这使我一直在处理文件。 当然,C ++库会尽可能使用std::string 。

char!=(signed char),char!=(unsigned char)

下面的代码编译,但chartypes的行为比inttypes的行为不同。 尤其是 cout << getIsTrue< isX<int8>::ikIsX >() << endl; cout << getIsTrue< isX<uint8>::ikIsX >() << endl; cout << getIsTrue< isX<char>::ikIsX >() << endl; 导致3种types的实例化模板:int8,uint8和char。 是什么赋予了? ints:int和uint32的结果是相同的模板实例化,并且另一个int是有符号的。 原因似乎是C ++将char,signed char和unsigned char看作三种不同的types。 int和signed int是一样的。 这是对的还是我错过了什么? #include <iostream> using namespace std; typedef signed char int8; typedef unsigned char uint8; typedef signed short int16; typedef unsigned short uint16; typedef […]

获取html页面上的所有链接?

我正在做一个小爱好项目。 我已经写了代码来获得一个URL,下载头,并返回MIMEtypes/内容types。 然而,在这之前的步骤是一个即时贴坚持 – 我需要检索基于内部标签的页面上的所有url的内容,并在引号即 … <link rel='shortcut icon' href="/static/favicon.ico" type="image/x-icon" /> … 会findfavicon链接。 在.net库中有没有什么有用的东西,或者这将是一个正则expression式的情况?

如何在Unix上使用C复制文件?

我正在寻找与Win32的CopyFile相当的Unix,我不想通过编写我自己的版本来重新发明轮子。

大数乘法,如何捕捉溢出

我正在寻找一个有效的(可选的标准,优雅和易于实现)的解决scheme来乘以相对较大的数字,并将结果存储为一个或多个整数: 假设我有两个64位整数声明如下: uint64_t a = xxx, b = yyy; 当我做a*b ,我怎么能检测到操作结果溢出,在这种情况下存储的地方进行? 请注意,我不想使用任何大数量的库,因为我存储数字的方式受到限制。

如何将参数添加到WebRequest中?

我需要从一个web服务调用一个方法,所以我写了这个代码: private string urlPath = "http://xxx.xxx.xxx/manager/"; string request = urlPath + "index.php/org/get_org_form"; WebRequest webRequest = WebRequest.Create(request); webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest. webRequest.ContentLength = 0; WebResponse webResponse = webRequest.GetResponse(); 但是这个方法需要一些参数,如下所示: 发布数据: _username:'API USER', // api authentication username _password:'API PASSWORD', // api authentication password 如何将这些参数添加到此Webrequest中? 提前致谢。

纯虚函数可能没有内联定义。 为什么?

纯虚拟函数是那些虚拟的成员函数,并具有纯指定符 ( = 0; ) C ++ 03 第10.4条第2款告诉我们什么是抽象类,作为一个附注,下面是: [注:一个函数声明不能​​同时提供一个纯粹的说明符和一个定义 – 结束注释] [例子: struct C { virtual void f() = 0 { }; // ill-formed }; – 例子] 对于那些对这个问题不太熟悉的人,请注意, 纯虚函数可以有定义,但是上面提到的条款禁止这样的定义出现在内联(lexically in-class)。 (对于定义纯虚函数的使用,您可能会看到,例如, GotW ) 现在所有其他types的function都可以提供一个一stream的定义,而这种限制似乎是乍看起来绝对是人为的和无法解释的。 想想看,似乎是这样的第二次和随后的一瞥:)但我相信如果没有一个具体的原因这个限制不会在那里。 我的问题是:有人知道这些具体原因吗? 好的猜测也是受欢迎的。 笔记: MSVC确实允许PVF具有内联定义。 所以不要感到惊讶:) 这个问题中的内联单词并不是指inline关键字。 这应该是词汇在课堂上

ConfigurationManager.AppSettings – 如何修改和保存?

这听起来可能听起来太琐碎,我也是按照文章中的build议做同样的事情,但是它并没有像预期的那样工作。 希望有人能指点我正确的方向。 我想保存每个AppSettings的用户设置。 一旦Winformclosures,我触发这个: conf.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (ConfigurationManager.AppSettings["IntegrateWithPerforce"] != null) ConfigurationManager.AppSettings["IntegrateWithPerforce"] = e.Payload.IntegrateCheckBox.ToString(); else config.AppSettings.Settings.Add("IntegrateWithPerforce", e.Payload.IntegrateCheckBox.ToString()); config.Save(ConfigurationSaveMode.Modified); 所以当第一次入口不存在的时候,它只会创build它,否则会修改现有的入口。 但是这并不能保存。 1)我做错了什么? 2)我在哪里等待App设置的用户设置再次保存? 它在Debug文件夹中还是在C:\ Documents and Settings \ USERNAME \ Local Settings \ Application Data文件夹中?

如何使用Console.WriteLine在列中alignment文本?

我有一种列显示,但最后两列似乎没有正确alignment。 这是我现在的代码: Console.WriteLine("Customer name " + "sales " + "fee to be paid " + "70% value " + "30% value"); for (int DisplayPos = 0; DisplayPos < LineNum; DisplayPos = DisplayPos + 1) { seventy_percent_value = ((fee_payable[DisplayPos] / 10.0) * 7); thirty_percent_value = ((fee_payable[DisplayPos] / 10.0) * 3); Console.WriteLine(customer[DisplayPos] + " " + sales_figures[DisplayPos] […]