对于下面的代码,我收到行标题中的错误
while((*(It2 + code)).exists){
Run Code Online (Sandbox Code Playgroud)
void locatetohashtable(std::list<Element> elist,
int *m,std::list<Element>& table,
std::list<std::string>& keylist )
{
std::list<Element>::iterator It2=table.begin();
int i=0;
int k=0;
std::list<Element>::iterator It;
for(It = elist.begin(); It != elist.end(); ++It)
{
int code=hash_func(stringIntValue((*It).name),*m,i);
while((*(It2 + code)).exists){
i++;
}
table.insert(*(It2+i), (*It));
keylist.insert(keylist.begin(),(*It).name);
k++;
}
}
Run Code Online (Sandbox Code Playgroud)
我没有得到同样的错误 ++It
有什么问题?
我已经在另一个问题中询问了multiset中的问题,但现在我发现我需要一个体面的理解,并且在互联网上找不到更复杂的例子.
你可以解释一下,也许是示例,multiset<A,B>A和B的作用和功能是什么,还有什么可以省略?我可以将A或B放到某个变量中吗?我真的很感激一些简短的例子或参考,
什么是Java的C++代码中的等价物:
#define printVar(var) cout<<#var<<"="<<var;
Run Code Online (Sandbox Code Playgroud)
打印字符串值及其名称.
我得到了一个(C++)代码,其中使用了数组
void fun(int *& name){...}
Run Code Online (Sandbox Code Playgroud)
但这背后的想法是什么?我想这意味着"一个引用数组"但是当你只是将一个指针传递给第一个很好的元素时,不是吗?那么这样做的动机是什么?
例如,包含三个整数的一维阵列可以定义为std::array<int, 3> myarray或myarray[3].是否有类似std::array<type, size>多维数组的容器myarray[3][3]?
假设我有一个函数,它采用某种形式的谓词:
void Foo( boost::function<bool(int,int,int)> predicate );
Run Code Online (Sandbox Code Playgroud)
如果我想用一个总是返回true的谓词来调用它,我可以定义一个辅助函数:
bool AlwaysTrue( int, int, int ) { return true; }
...
Foo( boost::bind( AlwaysTrue ) );
Run Code Online (Sandbox Code Playgroud)
但是无论如何调用这个函数(可能使用boost :: lambda)而不必定义一个单独的函数?
[编辑:忘了说:我不能使用C++ 0x]
我有这个代码构建和运行完美:
boost::function<void(string)> bar = boost::bind(&Bar::BarHandler, this, _1);
//Somewhere else in Bar.cpp
void Bar::BarHandler( std::string message ){
//Do stuff
}
Run Code Online (Sandbox Code Playgroud)
当我兴高采烈地改变boost通过std在上面的代码中,我开始收到此错误(我的编译器的Visual Studio 2010 SP1的):
c:\program files\microsoft visual studio 10.0\vc\include\xxpmfcaller(42): error C2664:
'void (std::string)' : cannot convert parameter 1 from 'boost::arg<I>' to 'std::string'
1> with
1> [
1> I=1
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> c:\program files\microsoft visual studio 10.0\vc\include\xxpmfcaller(52) : see reference to function …Run Code Online (Sandbox Code Playgroud) 这是我的问题,我需要创建X个文件并根据不同的事实写入它们,我的解决方案是创建一个像这样的ofstream指针向量
#include <boost/algorithm/string.hpp>
#include <vector>
#include<string>
#include <iostream>
#include <fstream>
vector<ofstream*> files;
files.resize(SplitVec.size()-4);
for(i=0;i<SplitVec.size()-4;i++)
{
line="/Users/jorge/Desktop/testing/strain_"+lexical_cast<string>(i);
cout<<"ine"<<endl;
files[i]=new ofstream(line.c_str());
}
Run Code Online (Sandbox Code Playgroud)
直到这一部分,它创建文件很好,后来在程序中我写给他们,这也很棒,我的问题是当我想要关闭对象,如果我使用:
for(i=0;i<SplitVec.size()-4;i++)
{
*files[i].close();
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
In file included from main.cpp:14:./methyl.h:298: error: request for member 'close' in 'files. std::vector<_Tp, _Alloc>::operator[] [with _Tp = std::ofstream*, _Alloc = std::allocator<std::ofstream*>](1ul)', which is of non-class type 'std::ofstream*'
Run Code Online (Sandbox Code Playgroud)
所以,我有一个问题,首先,为什么我不能调用close,它是指向ofstream的指针,所以使用*files [i],我会想象我可以关闭它,其次,如果我不关闭它,程序工作正常,但我几乎可以肯定,这是一个不好的做法,不想成为一个懒惰或蹩脚的程序员,我尽可能多地看,但我没有找到答案.谢谢!!!
假设我有以下声明的变量:
char mychararray[35];
Run Code Online (Sandbox Code Playgroud)
我想将数组中的每个字符设置为一个空格......我该怎么做?
我的导师告诉我我所要做的就是把
mychararray = "";
Run Code Online (Sandbox Code Playgroud)
但这根本不起作用......
我使用的是过时版本的 Visual Studio (2012),还是这只是一个错误的初始化?如果是后者,请说明如何使所有字符都为空格。
提前致谢!
我有
enum class ErrorLevel
{
VERBOSE,
DEBUG_,
INFORMATION,
WARNING,
ERROR
};
Run Code Online (Sandbox Code Playgroud)
这有效:
assertDetectionParameters( parameterSet, ErrorLevel::WARNING );
Run Code Online (Sandbox Code Playgroud)
这不会:
assertDetectionParameters( parameterSet, ErrorLevel::ERROR );
Run Code Online (Sandbox Code Playgroud)
错误 1 错误 C2589:“常量”:“::”右侧的非法标记
错误 2 错误 C2059:语法错误:“::”
Resharper 说:
“ErrorLevel 未命名值”
我的枚举中的某些名称出现此错误。