标签: visual-c++-2010

使用std :: wcout的C++中的高阶函数失败,错误C2248

我正在玩C++中实现功能风格的东西.目前,我正在寻找一种枚举文件的延续传递方式.

我有一些看起来像这样的代码:

namespace directory
{
    void find_files(
        std::wstring &path,
        std::function<void (std::wstring)> process)
    {
        boost::filesystem::directory_iterator begin(path);
        boost::filesystem::directory_iterator end;

        std::for_each(begin, end, process);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我这样称呼它:

directory::find_files(source_root, display_file_details(std::wcout));
Run Code Online (Sandbox Code Playgroud)

......这里display_file_details的定义如下:

std::function<void (std::wstring)>
    display_file_details(std::wostream out)
{
    return [&out] (std::wstring path) { out << path << std::endl; };
}
Run Code Online (Sandbox Code Playgroud)

计划是通过延续find_files,但能够将组合函数传递给它.

但我得到错误:

error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' :
    cannot access private member declared in
    class 'std::basic_ios<_Elem,_Traits>'
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?尝试这个我是疯了吗?

注意:我的功能术语(高阶,延续等)可能是错误的.随意纠正我.

c++ functional-programming visual-c++-2010

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

Foo&foo = Bar()是合法的还是编译器问题

struct Foo {};
struct Bar : Foo {};

Foo &foo = Bar(); // without const
Run Code Online (Sandbox Code Playgroud)

正如在这个问题的答案和评论中写的那样,我无法为引用分配右值.但是,我可以编译此代码(MSVC++ 2010)而不会出现错误或警告.这是我的编译器的已知问题吗?

c++ reference visual-c++ visual-c++-2010

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

警告C6269:操作顺序可能不正确:取消引用被忽略

我对vs 2010上的c ++代码运行代码分析我在这些行上遇到错误

va_arg(argList, TCHAR_ARG);
va_arg(argList, int*);
Run Code Online (Sandbox Code Playgroud)

警告C6269:操作顺序可能不正确:取消引用被忽略

在这两条线路上收到警告的原因是什么?

我在Switch案件上遇到错误

case 'C':
case 'C'|_atltmpFORCE_ANSI:
case 'C'|_atltmpFORCE_UNICODE:
case 'o';
case 'p':
case 'n':
Run Code Online (Sandbox Code Playgroud)

完整的代码

inline void CXString::FormatV(LPCTSTR lpszFormat, va_list argList)
{
    va_list argListSave = argList;

    // make a guess at the maximum length of the resulting string
    int nMaxLen = 0;
    for (LPCTSTR lpsz = lpszFormat; *lpsz != '\0'; lpsz = CharNext(lpsz))
    {
        // handle '%' character, but watch out for '%%'
        if (*lpsz != '%' || *(lpsz = CharNext(lpsz)) == …
Run Code Online (Sandbox Code Playgroud)

c++ code-analysis visual-c++ visual-c++-2010

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

Lambda函数无法在Visual Studio 2010中编译

我更感兴趣的是知道它为什么不编译而不是修复代码.

致命错误C1001:编译器中发生内部错误.

int main()
{
    class MyClass
    {
    public:
        MyClass(const std::string & name)
            : name_(name) {}
        std::string name_;
    };

    auto creator = []() -> MyClass *
    {
        return new MyClass("Hello World");
    };

    MyClass * pMyClass = creator();

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

c++ visual-c++ visual-c++-2010 c++11

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

错误:标识符"list"未定义(Visual C++新增)

我只想在Visual C++上初始化List,但是我遇到以下错误:

  • 错误:标识符"list"未定义
  • 错误C2065:'list':未声明的标识符

为什么会这样?

我的包括:

#include "stdlib.h"
#include "malloc.h"
#include "stdio.h"
#include <set>
#include <vector>
#include <string>
#include <list>
#include "stdafx.h"
#include <iostream>
#include <io.h>
#include <fcntl.h>
#include <fstream>
#include <WebServices.h>
#include "./WCF_managed_app.xsd.h"
#include "./WCF_managed_app_Client.wsdl.h"
#include "./WCF_managed_app_Client.xsd.h"
#include "./schemas.microsoft.com.2003.10.Serialization.xsd.h"
Run Code Online (Sandbox Code Playgroud)

visual-c++ visual-c++-2010

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

visual studio 2012 c ++没有cout

我正在尝试学习c ++,但是像"cout"和"cin"这样的简单方法不存在这是我的代码:

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


int _tmain(int argc, _TCHAR* argv[])
{
    cout>>"hello";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

有一个错误,上面写着"错误C2065:'cout':未声明的标识符"

和"智能感知:标识符"cout"未定义"

c++ visual-c++-2010 visual-studio-2012

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

生成两个具有90%相同元素的随机位数组

我必须生成两个随机位数组.要求是生成只有10%误码率的数组,即2个数组之间的元素比较应该给我们大约90%的元素.

我分别使用rand函数生成数组,它导致两个数组中大约40%到60%的相同元素.为了减少到10%,我试图在一个数组中找到随机位置以将其替换为1,但它会破坏随机性.它可能不是优雅的方式,对于大数字它不起作用(我需要测试数组中的10,000位).任何人都可以建议我如何生成两个错误非常少的随机二进制数组.

c++ visual-c++-2010

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

C++中的Const过程,Visual Studio C++ 2010中的奇怪错误?

class a{
public:
    int b;
    static int c;
    virtual void mod() const
    {
        c=4;
    }

};



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

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

看看这个...使用Visual Studio C++ 2010编译器编译之后,我得到......

cpplearningconsole.obj:错误LNK2001:未解析的外部符号"public:static int a :: c"(?c @ a @@ 2HA)

我想这是一个编译器错误.对我来说,真正的问题是.如果它是const,mod应该能修改吗?

谢谢.

c++ visual-c++-2010

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

如何让屏幕暂停?

可能重复:
如何阻止C++控制台应用程序立即退出?

所以即时学习c ++和我给出了这个例子,我想运行它.但我不能让它熬夜,除非我改变它.在我发布之后,如何让Microsoft Visual 2010在屏幕到达程序结束时保持屏幕状态?

#include<iostream>
using namespace std;

int area(int length, int width);        /* function declaration */

/* MAIN PROGRAM: */
int main()
{
    int this_length, this_width;      

    cout << "Enter the length: ";             /* <--- line 9 */
    cin >> this_length;
    cout << "Enter the width: ";
    cin >> this_width;
    cout << "\n";                             /* <--- line 13 */

    cout << "The area of a " << this_length << "x" << this_width;
    cout << " rectangle is " << …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++ visual-c++-2010

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

获取错误LNK2019:vS中未解析的外部符号@)!)在VC 6.0中编译正常

我试图用VS2010 C++编译器编译一个14岁的C++程序(不要问为什么:().我收到以下错误

错误10错误LNK2019:未解析的外部符号"public:__thiscall CConfiguration :: CConfiguration(void)"(?? 0CConfiguration @@ QAE @ XZ)在函数"public:__thiscall CWhoisService :: CWhoisService(void)"中引用(?? 0CWhoisService @ @ QAE @ XZ)

我有一个带有头CWhoisService.h的cpp文件CWhoisService.cpp

CWhoisService.h:

class CWhoisService
{
public:
    HRESULT Initialize(const char * szServiceName, REFCLSID pMetricsCLSID);

CWhoisService();
~CWhoisService();
HRESULT CheckService();

protected:

    CConfiguration m_Configuration;    
protected:
    bool           m_bStartedEvenLog;
    bool           m_bStartedConfiguration;

private:
       //Don't want standard constructor to be called
};
Run Code Online (Sandbox Code Playgroud)

CWhoisService.cpp

#include "ConfigurationLib.h"
#include "CWhoisService.h"

CWhoisService::CWhoisService():
    m_bStartedEvenLog(false),
    m_bStartedConfiguration(false) 
{

}
HRESULT CWhoisService::Initialize(const char * szServiceName, REFCLSID pMetricsCLSID)
{
    HRESULT hr = S_OK;
    //Initialize the configuration library …
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio-2010 visual-c++-2010

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