小编bil*_*llz的帖子

C ++ find_if找不到谓词

我收到错误消息:

no matching function for call to ‘findByPosition::findByPosition(std::vector<int>::size_type&, std::vector<int>::size_type&)’
Run Code Online (Sandbox Code Playgroud)

当我投ikint我得到:

no matching function for call to ‘findByPosition::findByPosition(int, int)’
Run Code Online (Sandbox Code Playgroud)

我不知道我的谓词有什么问题。我已经()根据需要重载了运算符:

struct findByPosition
{
    const Node needle;
    findByPosition(const Node& sought) : needle(sought) {}
    bool operator()(int i,int j) const
    {
        return ((needle.i == i) && (needle.j == j));

    }
};

SparseMatrix& SparseMatrix::operator*=(const SparseMatrix &other)
{
    SparseMatrix SparseMatrixResult(_numRow, other._numCol);
    vector<Node>::iterator rowMulti, colMulti;

    if(_numCol != other._numRow)
    {
        // error multiplying
    }

    for(std::vector<int>::size_type i = 0; i != …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm vector

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

无法将元素添加到链接列表的末尾

我试图在链接列表的后面添加一个元素但它似乎没有添加,有人可以告诉我我的代码有什么问题谢谢.我的链接列表不为空

void LinkedList::Addelementfromback(VoidPtr horoscope)
{
   NodePtr temp = head;  

   while (temp != NULL)
   {
    temp=temp->next;
   }

    NodePtr element=new Node;

    element->data=horoscope;

    element->next=NULL;

    temp=element;
}
Run Code Online (Sandbox Code Playgroud)

c++ debugging linked-list

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

这是什么意思?

在·std :: unique_ptr·文件"memory"中的代码中,我将操作符重载函数视为

typename tr1::add_reference<_Ty>::type operator*() const
{   
   // return reference to object
   return (*this->_Myptr);
}

pointer operator->() const
{
  // return pointer to class object
   return (&**this);
}
Run Code Online (Sandbox Code Playgroud)

&**第二个函数的意思是什么?谢谢.

c++ smart-pointers operator-overloading

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

在vs2012中移动一个字符串

std::string t1("aaa");
const char *p = t1.c_str();
std::string t2(std::move(t1));
if (p == t2.c_str()) {
    std::cout << "ok!" << std::endl;    
}
Run Code Online (Sandbox Code Playgroud)

此代码在vs2012中没有打印.它只是使用memmove内部字符串复制t1t2.为什么?

c++ string move c++11

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

在一组c ++中访问字符串的第一个字母

我有一组字符串,我需要访问每个字符串,并将字符串的第一个字母与一个char进行比较,如果它们相同则停止。我该如何处理?我尝试过

char* p;

for (std::set<string>::iterator iter=myset.begin(); iter!=myset.end();iter++)
    {p = *iter;
    if (p==characterForComparison) return 0;
    }
Run Code Online (Sandbox Code Playgroud)

但这并没有通过编译器,它说

error C2440: '=' : cannot convert from 'std::basic_string<_Elem,_Traits,_Ax>' to 'char *'
Run Code Online (Sandbox Code Playgroud)

我该如何解决?我需要的非常简单,因此我需要一个尽可能简单的解决方案,只需遍历所有字符串,比较第一个字母,如果相同,则返回0;否则,返回0。

c++ string iterator set

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

是否建议使用三元运算符?

在C中,我们可以使用三元组

( a == 4) ? a = b: a = 5;
Run Code Online (Sandbox Code Playgroud)

有人告诉我最好不要使用它,你怎么看?

c++

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

试图通过system()运行字符串命令

如何将字符串转换为可以通过system()执行的字符串?

我有这个

std::string out = "some command to run" + some_string_variable;
system(out);
Run Code Online (Sandbox Code Playgroud)

这将无法编译,它给我一个转换错误

从std :: string到const char*没有合适的转换函数

但如果我试着跑

system("pause");
Run Code Online (Sandbox Code Playgroud)

这样可行

c++ windows string visual-studio-2010

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

如何删除STL指针列表?

我有一对配对列表.迭代列表并删除第一个和第二个元素是一个好主意吗?其中的对象分配有新的.

list<pair<string,GraphObject*>>* table;
for(i=0; i< length; i++){
    it = table[i].begin();
    while(it != table[i].end()){
        delete (*it).second;
        delete &(*it).first;
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:字符串没有分配新,我知道现在我没有删除它.可以这样删除第二个吗?

c++ iterator memory-leaks stl list

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

visual Studio奇怪的行为

我在visual studio 2010中编写了一个c ++代码,作为我的大三学生的一个例子

#include <iostream>
using namespace std;
int main()
{
    cout<< "How are Your";
}
Run Code Online (Sandbox Code Playgroud)

我不明白这个程序如何构建和执行没有return语句,如果任何人可以为我解释?

c++ visual-studio-2010

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

从函数返回本地字符数组

如何从一个函数返回本地字符数组

char* testfunction()
{
char array[] = "Hello World";
 return array;
}

char main()
{
 char* array = testfunction();
 printf(" %s -> string", array);
 return 0;
}
Run Code Online (Sandbox Code Playgroud)

这些代码会导致未知错误

@ $ @ < Ʉ؅ ; Y@ - >字符串

c c++ string pointers visual-c++

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