有没有的等效__DATE__和__TIME__C#中?
基本上我要做的是在C#应用程序中放置一些构建时间戳.
我在微软网站上看到的一种可能性是做以下事情:
Assembly assem = Assembly.GetExecutingAssembly();
Version vers = assem.GetName().Version;
DateTime buildDate = new DateTime(2000, 1, 1).AddDays(vers.Build).AddSeconds(vers.Revision * 2);
Console.WriteLine(vers.ToString());
Console.WriteLine(buildDate.ToString());
Run Code Online (Sandbox Code Playgroud)
但是,这仅适用于AssemblyInfo.cs中的版本为"1.0 .. ",而我们的版本不是.
我有一个同名的静态和动态库:libclsocket.a和libclsocket.so当我指定要链接到的库时,我只需输入-lclsocket作为库.我的程序符合并运行完美,但我使用的是什么库?静态库还是动态库?我想给我的朋友我的程序,我不确定我是否需要在发布中包含库.C++,codelite,pcLinuxOS 2010
让我们说我有一个:
#include <utility>
using namespace std;
typedef pair<int, int> my_pair;
Run Code Online (Sandbox Code Playgroud)
如何初始化const my_pair?
有没有人知道是否有一个事实上的标准(即TR1或Boost)C++函数对象来访问std :: pair的元素?在过去24小时内,我曾两次希望我有类似keysPerl哈希函数的功能.例如,在std :: map对象上运行std :: transform并将所有键(或值)转储到另一个容器会很不错.我当然可以编写这样一个函数对象,但我更愿意重用那些有很多眼球的东西.
我有一个C#程序集,由C#应用程序引用.
由于我们的编码标准,有一个规则,调试DLL后缀为"d"(例如ProjectA.dll变为ProjectAd.dll).当我将重命名的DLL的引用添加到应用程序时,它会成功构建,但会FileNotFoundException在执行时抛出.
抛出的错误如下:
System.IO.FileLoadException: Could not load file or assembly 'ProjectA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=49df7f988e86ed92' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'ProjectA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=49df7f988e86ed92'
程序集管理器也会发出警告并报错:
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
从错误消息,它看起来像是在寻找没有d后缀的程序集.
顺便说一句,有一个由同一个应用程序引用的C++/CLI程序集.它d附加到DLL,但在VS2005中查看引用的属性表明安全标识已d正确附加.C#的文献并没有 …
我有一个小程序,我想执行测试
#include <map>
#include <iostream>
using namespace std;
struct _pos{
float xi;
float xf;
bool operator<(_pos& other){
return this->xi < other.xi;
}
};
struct _val{
float f;
};
int main()
{
map<_pos,_val> m;
struct _pos k1 = {0,10};
struct _pos k2 = {10,15};
struct _val v1 = {5.5};
struct _val v2 = {12.3};
m.insert(std::pair<_pos,_val>(k1,v1));
m.insert(std::pair<_pos,_val>(k2,v2));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我尝试编译它时,我收到以下错误
$ g++ m2.cpp -o mtest
In file included from /usr/include/c++/4.4/bits/stl_tree.h:64,
from /usr/include/c++/4.4/map:60,
from m2.cpp:1:
/usr/include/c++/4.4/bits/stl_function.h: In member function ‘bool std::less<_Tp>::operator()(const _Tp&, …Run Code Online (Sandbox Code Playgroud) 所以我有一套 pairs<string ,string>
我想用来find()搜索一对字符串,这个字符串位于该对的"第一个"中,然后如果我首先找到该字符串,我想从该函数返回第二个字符串.
我目前的尝试是......
myList::iterator i;
i = theList.find(make_pair(realName, "*"));
return i->second;
Run Code Online (Sandbox Code Playgroud) 根据cppreference:
在不等式比较(<,>)中,首先比较第一个元素,并且只有当不等式比较不适用于它们时,才比较第二个元素.
这意味着:
return ((a.first < b.first) || (!(b.first < a.first) && (a.second < b.second)));
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么它如此不直观?它背后的原因是什么?是否存在这种推理导致正确答案的例子?
我认为实施将只是:
return a.first < b.first && a.second < b.second
Run Code Online (Sandbox Code Playgroud) 如果我有一个容器(vector,list等),其中每个元素都是a std::pair,是否有一种简单的方法来迭代每对元素的每个元素?
即
std::vector<std::pair<int,int> > a;
a.push_back(std::pair(1,3));
a.push_back(std::pair(2,3));
a.push_back(std::pair(4,2));
a.push_back(std::pair(5,2));
a.push_back(std::pair(1,5));
Run Code Online (Sandbox Code Playgroud)
然后能够迭代该值:1,3,2,3,4,2,5,2,1,5?
类似地,什么类型的仿函数/函数会返回一个容器(相同类型),如上所述的对元素的扁平列表?
我的应用程序中有一个图像,我的winforms中有一张图片
public static string Correct_Icons = @"C:\Users\xyz\Documents\Visual Studio 2008\Projects\FileShareMgmt\FileShareMgmt\Resources\Correct.png";
public static string warning_Icon = @"C:\Users\xyz\Documents\Visual Studio 2008\Projects\FileShareMgmt\FileShareMgmt\Resources\Warning.png";
cell.Value = Image.FromFile("Resources/warning_Icon);
Run Code Online (Sandbox Code Playgroud)
但我想要的只是相对路径而不是完整路径.
我想要这个
public static string Correct_Icons = "\Resources\Correct.png";
Run Code Online (Sandbox Code Playgroud)
和续 .... /不工作