我知道如何做到这一点:通过创建一个必要大小的字节数组并使用for循环来转换int数组中的每个元素.
我想知道是否有更快的方法,因为如果int大于一个方法,上面的方法似乎会破裂sbyte.
有没有办法从列表中获取int的索引?寻找像list1.FindIndex(5)我想要在列表中找到5的位置的东西.
我希望使用-fsanitize=memoryclang中的标志来分析如下的程序:
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
void writeToFile(){
ofstream o;
o.open("dum");
o<<"test"<<endl; //The error is here.
//It does not matter if the file is opened this way,
//or with o("dum");
o.close();
}
int main(){
writeToFile();
}
Run Code Online (Sandbox Code Playgroud)
据我所知,这个程序是正确的,但是当我使用clang++ san.cpp -fsanitize=memory它时失败(在运行时):
UMR in __interceptor_write at offset 0 inside [0x64800000e000, +5)
==9685== WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x7f48d0899ae5 (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x7bae5)
#1 0x7f48d08d1787 (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xb3787)
#2 0x7f48d08d21e2 (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xb41e2)
#3 0x7f48d08cfd1e (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xb1d1e)
#4 0x7f48d08b1f2d (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x93f2d)
#5 0x7f48d16d60f5 in writeToFile() /home/daniel/programming/test/santest.cpp:10 …Run Code Online (Sandbox Code Playgroud) 可能重复:
禁用Eclipse的错误发现.(Codan误报)
到目前为止,使用GCC 4.8/Clang 3.3 C++支持Eclipse正在进行语法检查(在功能支持方面),Eclipse将许多事情标记为实际上有效代码的错误(模板别名恰好是我的主要问题,但是还有其他问题).
当我编译(或尝试无论如何,遇到一些问题,请参阅此处了解更多)无论编译器正在做什么工作都能完成它的工作,并且它的错误会被传播,但是它所说的代码仍然可以强调(红色分别是错误和警告的金蜘蛛,这使得查看正在发生的事情变得更加困难.
有没有办法摆脱这些错误/警告?
更好的方法是只有在编译尝试之后才能摆脱警告,并且只要代码的相关部分没有改变,但仍然保持它们一般启用.
(实际上最好的是Eclipse的插件,它支持所有,或至少比Juno本身更多的C++ 11,但我似乎无法找到它)
所以我只想找到给定数字的所有除数(除了数字本身).目前,我有这个:
public static List<int> proper_divisors(int x)
{
List<int> toreturn = new List<int>();
toreturn.Add(1);
int i = 0;
int j=1;
int z = 0;
while (primes.ElementAt(i) < Math.Sqrt(x))
{
if (x % primes.ElementAt(i) == 0)
{
toreturn.Add(primes.ElementAt(i));
toreturn.Add(x / primes.ElementAt(i));
j = 2;
z = (int)Math.Pow(primes.ElementAt(i), 2);
while (z < x)
{
if (x % z == 0)
{
toreturn.Add(z);
toreturn.Add(x / z);
j++;
z = (int)Math.Pow(primes.ElementAt(i), j);
}
else
{
z = x;
}
}
}
i++;
}
toreturn = …Run Code Online (Sandbox Code Playgroud) 有没有办法创建一个可以合理地适合页面的clang调用图?
即给出:
#include<iostream>
using namespace std;
int main()
{
int a;
cin>>a;
cout<<a;
cout<<a;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我目前得到 
通过使用:
$ clang++ main.cpp -S -emit-llvm -o - |
opt -analyze -std-link-opts -dot-callgraph
$ cat callgraph.dot | c++filt |
sed 's,>,\\>,g; s,-\\>,->,g; s,<,\\<,g' |
gawk '/external node/{id=$1}$1!=id' | dot -Tpng -ocallgraph.png
Run Code Online (Sandbox Code Playgroud)
(这似乎是很多努力去做一些我不希望这么困难的事情).我想在横轴上得到一些更合理的东西.Unflatten似乎没有任何影响(至少在这个文件上,对其他文件似乎影响很小).
有没有办法确保png生成的文件可以舒适地适合页面(任何标准大小)?
注意:上面的代码来自生成C++代码的调用图
更新:设置页面="8.5,11"给出以下内容:

可能重复:
修改Dictionary中的Struct变量
为什么会这样
MyStruct test = new MyStruct();
test.Closed = true;
Run Code Online (Sandbox Code Playgroud)
效果很好,但是
MyDictionary[key].Closed = true;
Run Code Online (Sandbox Code Playgroud)
在编译时显示"无法修改表达式,因为它不是变量"错误?
为什么这两种情况下的任务有所不同?
注意:MyDictionary属于类型<int, MyStruct>
结构代码:
public struct MyStruct
{
//Other variables
public bool Isclosed;
public bool Closed
{
get { return Isclosed; }
set { Isclosed = value; }
}
//Constructors
}
Run Code Online (Sandbox Code Playgroud) 我觉得我做的事情很傻,但问题在于:
Function getPropertyOfFile($a, $b, $c)
{
$a.GetDetailsOf($b, $c)
}
Run Code Online (Sandbox Code Playgroud)
如果我传递适合该函数的$ a,$ b,$ c变量,它就会失败
"方法调用失败,因为[System.Object []]不包含名为'GetDetailsOf'的方法."
但是,如果我直接用我传递的参数替换$ a,$ b,$ c,然后尝试运行它,它运行正常.
到底他妈发生了什么?
注意:我正在使用PowerShell ISE,并通过将其复制/粘贴到控制台中来将函数输入到powershell.我也一直在假设如果我输入一个具有相同名称的新函数,它将覆盖.是否有更好的方法来从.ps1中读取PS?
编辑:我试图将这个问题的答案包装成函数.
编辑2:
Function getPropertyOfFile $a $b $c
{
$a.GetDetailsOf($b, $c)
}
Run Code Online (Sandbox Code Playgroud)
给出Missing function body in function declaration.
At line:1 char:28错误.
更准确地说,int是Integer类的一部分(一个精简版或其他东西),还是完全不同的东西?
我知道int是一个值类型而Integer是一个引用类型,但int是否仍然从Object继承?
(我假设在这方面int,long,boolean等都是相似的.为方便起见,只选择了int)
可能重复:
Resharper:vars
是否有一个原因,resharper暗示var thing1 = 5相反int thing1 = 5?它似乎意味着完全相同的东西,除了var对于人类读者来说更难/更难以理解.我很想知道编译器解释它们的方式是否存在差异,或者它是否仅仅是语法糖.
c# ×5
c++ ×2
arrays ×1
c++11 ×1
call-graph ×1
clang ×1
clang++ ×1
eclipse-cdt ×1
find ×1
graphviz ×1
inheritance ×1
java ×1
libstdc++ ×1
list ×1
msan ×1
powershell ×1
primitive ×1
resharper ×1
struct ×1