小编Ane*_*nan的帖子

从地图中获取价值

我有一张地图,即valueMap

typedef std::map<std::string, std::string>MAP;
MAP valueMap;
...
// Entering data.
Run Code Online (Sandbox Code Playgroud)

然后我通过引用将此映射传递给函数

void function(const MAP &map)
{
  std::string value = map["string"];
  // By doing so I am getting an error.
}
Run Code Online (Sandbox Code Playgroud)

如何从地图中获取值,该值作为函数的引用传递?

c++ dictionary stdmap

45
推荐指数
2
解决办法
11万
查看次数

在VS2010中删除项目依赖项时出错

我有一个包含大量项目的大型解决方案.有些项目依赖于其他项目(尽管不是循环依赖项).

当我尝试删除项目的依赖项时,我收到一条错误消息,例如"项目系统添加了依赖项,无法删除".导致此错误的原因是什么?我怎么能解决这个问题?

dependency-properties project visual-studio-2010

37
推荐指数
3
解决办法
2万
查看次数

使用std :: sort对std :: lists进行排序

可能重复:
使用stl排序函数排序列表
为什么只有std :: list :: sort()?

我的问题是我们可以使用std :: sort函数对两个std :: lists进行排序吗?我有2个字符串列表

  std::list<std::string>list1, list2;
  .....//entering values to list
  std::sort(list1.begin(), list1.end());

  std::sort(list2.begin(), list2.end());
Run Code Online (Sandbox Code Playgroud)

虽然我正在整理这些列表,但我收到了错误.我尝试使用std :: vector,此时排序有效.

错误就像

C:\ Program Files(x86)\ Microsoft Visual Studio 10.0\VC\include\xutility(1158):请参阅'std :: operator - '1> C:\ Program Files(x86)\ Microsoft Visual Studio 10.0\VC的声明\ include\algorithm(3642):错误C2784:'_ Base1 :: difference_type std :: operator - (const std :: _ Revranit <_RanIt,_Base>&,const std :: _ Revranit <_RanIt2,_Base2>&)':不能从'std :: _ List_iterator <_Mylist>'1>推导'const std :: _ Revranit <_RanIt,_Base>&'的模板参数1> [1> _Mylist = std :: _ List_val> 1>] …

c++ sorting list std

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

将std :: string作为const引用返回

我对将std :: string作为const引用返回有疑问.

class sample
{
public:
  std::string mString;
  void Set(const std::string& s)
  {
    mString = s;
  }
  std::string Get()
  {
    return mString;
  }
 };
Run Code Online (Sandbox Code Playgroud)

在Set函数中,我将std :: string作为const引用传递给const,因为它的值在函数内部没有变化.

而在Get功能中,实际上我在这里很困惑.返回std :: string作为值更有意义.但我不确定,通过传递字符串作为const引用有任何好处.通过回转字符串作为参考将增加exectuion速度,我想是的,但我不确定.但是将它作为'const返回可以为此带来任何好处?

c++ string const reference stdstring

11
推荐指数
3
解决办法
3万
查看次数

发布模式中的断点

我正在使用(c ++)visual studio 2010.

我必须跟踪我的应用程序的控制流程.所以我在源代码中设置了一个断点

在调试模式下运行应用程序时,断点会命中.但在realease模式下,它没有受到打击.

那么请建议一个解决方案来解决发布模式中的断点???

visual-studio-2010

7
推荐指数
4
解决办法
1万
查看次数

Sleep()函数用法

这是一个检查Sleep()函数功能的示例pgm.这是一个演示,因为我在我的app开发中使用了这个sleep()和clock()函数.

  // TestTicks.cpp : Defines the entry point for the console application.
  //

  #include "stdafx.h"
  #include<iostream>
  #include<iomanip>
  #include <Windows.h>

  int _tmain(int argc, _TCHAR* argv[])
  {
    int i, i2;
    i = clock();
    //std::cout<<" \nTime before Sleep() : "<<i;
    Sleep(30000);
    i2 = clock();
    //std::cout<<" \nTime After Sleep() : "<<i2;
    std::cout<<"\n Diff : "<<i2 -i;
    getchar();
      return 0;
  }
Run Code Online (Sandbox Code Playgroud)

在这段代码中,我在睡眠功能之前和之后使用clock()来计算时间.由于iam使用sleep(30000),时间差异至少为30000.

我已多次运行此prgm.打印输出为30000,30001,30002.这些都可以.但有时我得到像29999和29997这样的值.这怎么可能,因为我把30000睡眠时钟().

请告诉我原因.

c++ sleep timing clock

7
推荐指数
1
解决办法
3万
查看次数

CreateThread函数的多个参数

当我使用CreateThread API方法时,当我想传递LPVOID lpParameter传递的多个参数时,我需要做什么?

c++ createthread

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

杀死正在运行的线程

如果我们强行杀死正在运行的线程会发生什么

我有一个线程RecordThread(),它调用一些复杂和耗时的函数.在这些函数中,我使用try-catch块,分配和释放内存以及使用临界区变量等.

喜欢

  void RecordThread()
  {
    AddRecord();
    FindRecord();
    DeleteRecord();
    // ...
    ExitThread(0);
   } 
Run Code Online (Sandbox Code Playgroud)

创建此线程后,我会在线程完成执行之前立即将其删除.在这种情况下,如果强行杀死线程会发生什么?我们杀死线程后AddRecord,内部函数(,DeleteRecord)是否完成执行?

c++ windows multithreading

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

auto_ptr指向动态数组

在我的代码中,我使用new分配一个整数数组.之后我将这个指针包装到auto_ptr.我知道auto_ptr会自动调用它的析构函数.由于我的auto_ptr指向一个数组(使用new分配),数组是否会与auto_ptr一起被删除,否则会导致内存泄漏.这是我的示例代码.

std::auto_ptr<int> pointer;

void function()
{
  int *array = new int[2];
  array[0] = 10;
  array[1] = 20;

  pointer.reset((int*) array);
}

int _tmain(int argc, _TCHAR* argv[])
{

    function();
return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ auto-ptr

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

auto_ptr到正常的指针转换

我们能够将std :: auto_ptr转换为普通指针吗?

    class Test
    {
     ......
    }

    Test* function()
    {
      std::auto_ptr<Test> test(new Test());

      return _____//TODO : need to convert this auto_ptr to Test*
    }
Run Code Online (Sandbox Code Playgroud)

是否可以将本地创建的auto_ptr指针转换为普通指针.

c++ pointers auto-ptr

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