Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 此语法中的构造函数转换错误_C++_Visual Studio - Fatal编程技术网

C++ 此语法中的构造函数转换错误

C++ 此语法中的构造函数转换错误,c++,visual-studio,C++,Visual Studio,我试图从MSVS 2017中构建一个示例 #include <fstream> #include <vector> #include <algorithm> #include <iterator> #include <iostream> int main() { std::ifstream in("file.lib", std::fstream::in); const std::vec

我试图从MSVS 2017中构建一个示例

  #include <fstream>
  #include <vector>
  #include <algorithm>
  #include <iterator>
  #include <iostream>

  int main() {
      std::ifstream in("file.lib", std::fstream::in);

      const std::vector<char> buffer = []() {
        std::vector<char> buffer_(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>());
        std::replace(buffer_.begin(), buffer_.end(), '\n', ' ');
        std::replace(buffer_.begin(), buffer_.end(), '\\', ' ');
        return buffer_;
      } ();

    return 0;
}


#包括
#包括
#包括
#包括
#包括
int main(){
std::ifstream-in(“file.lib”,std::fstream::in);
常量std::向量缓冲区=[](){
std::向量缓冲区(std::istreambuf_迭代器(in),std::istreambuf_迭代器());
替换(缓冲区开始(),缓冲区结束(),'\n','';
std::replace(buffer\.begin()、buffer\.end()、'\\'、'';
返回缓冲区;
} ();
返回0;
}
我有几个问题:

λ cmake --build .
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  Checking Build System
  CMake does not need to re-run because C:/Users/mulderpa/cppsandbox/sdb2/build/CMakeFiles/generate.stamp is up-to-date.
  Building Custom Rule C:/Users/mulderpa/cppsandbox/sdb2/CMakeLists.txt
  CMake does not need to re-run because C:/Users/mulderpa/cppsandbox/sdb2/build/CMakeFiles/generate.stamp is up-to-date.
  main.cc
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(18): error C2228: left of '.begin' must have class/struct/union [C:\Users\mulderpa\cppsandbox\sdb2\build\main.v cxproj]
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(18): error C2672: 'std::replace': no matching overloaded function found [C:\Users\mulderpa\cppsandbox\sdb2\buil d\main.vcxproj]
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(18): error C2780: 'void std::replace(const _FwdIt,const _FwdIt,const _Ty &,const _Ty &)': expects 4 arguments -  3 provided [C:\Users\mulderpa\cppsandbox\sdb2\build\main.vcxproj]
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\algorithm(1607): note: see declaration of 'std::repl
  ace'
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(19): error C2672: 'std::replace': no matching overloaded function found [C:\Users\mulderpa\cppsandbox\sdb2\buil d\main.vcxproj]
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(19): error C2780: 'void std::replace(const _FwdIt,const _FwdIt,const _Ty &,const _Ty &)': expects 4 arguments -  3 provided [C:\Users\mulderpa\cppsandbox\sdb2\build\main.vcxproj]
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\algorithm(1607): note: see declaration of 'std::repl
  ace'
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(21): error C2440: 'initializing': cannot convert from 'std::vector<char,std::allocator<char>> (__cdecl *)(std:: istreambuf_iterator<char,std::char_traits<char>>,std::istreambuf_iterator<char,std::char_traits<char>> (__cdecl *)(void))' to 'std::vector<char,std::allo cator<char>>' [C:\Users\mulderpa\cppsandbox\sdb2\build\main.vcxproj]
  C:\Users\mulderpa\cppsandbox\sdb2\main.cc(21): note: No constructor could take the source type, or constructor overload resolution was ambiguous

λcmake——构建。
Microsoft(R)针对.NET Framework的生成引擎版本15.9.21+g9802d43bc3
版权所有(C)微软公司。版权所有。
检查生成系统
CMake不需要重新运行,因为C:/Users/mulderpa/cppsandbox/sdb2/build/CMakeFiles/generate.stamp是最新的。
构建自定义规则C:/Users/mulderpa/cppsandbox/sdb2/CMakeLists.txt
CMake不需要重新运行,因为C:/Users/mulderpa/cppsandbox/sdb2/build/CMakeFiles/generate.stamp是最新的。
main.cc
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(18):错误C2228:“.begin”的左侧必须具有类/struct/union[C:\Users\mulderpa\cppsandbox\sdb2\build\main.v cxproj]
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(18):错误C2672:“std::replace”:未找到匹配的重载函数[C:\Users\mulderpa\cppsandbox\sdb2\buil d\main.vcxproj]
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(18):错误C2780:“void std::replace(const\u FwdIt,const\u FwdIt,const\u Ty&,const\u Ty&”):需要4个参数-提供3个[C:\Users\mulderpa\cppsandbox\sdb2\build\main.vcxproj]
C:\ProgramFiles(x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\algorithm(1607):注意:请参见“std::repl”的声明
王牌
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(19):错误C2672:“std::replace”:未找到匹配的重载函数[C:\Users\mulderpa\cppsandbox\sdb2\buil d\main.vcxproj]
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(19):错误C2780:“void std::replace(const\u FwdIt,const\u FwdIt,const\u Ty&,const\u Ty&”):需要4个参数-提供3个[C:\Users\mulderpa\cppsandbox\sdb2\build\main.vcxproj]
C:\ProgramFiles(x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include\algorithm(1607):注意:请参见“std::repl”的声明
王牌
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(21):错误C2440:“初始化”:无法从“std::vector(uu-cdecl*)(std::istreambuf\u迭代器,std::istreambuf\u迭代器(u-cdecl*)(void))”转换为“std::vector”[C:\Users\mulderpa\cppsandbox\sdb2\build\main.vcxproj]
C:\Users\mulderpa\cppsandbox\sdb2\main.cc(21):注意:没有构造函数可以采用源类型,或者构造函数重载解析不明确

不确定,我能够用g++fine构建示例。

注释说明问题-
缓冲区
被解析为函数声明,请参阅。另外,您的lambda不会捕获流中的
,而该流肯定不会编译

解决方案是用
buffer{}
替换
buffer}
,并在
中捕获

const std::vector<char> buffer = [&in]() {
        std::vector<char> buffer_{std::istreambuf_iterator<char>(in),
                                  std::istreambuf_iterator<char>()};
        std::replace(buffer_.begin(), buffer_.end(), '\n', ' ');
        std::replace(buffer_.begin(), buffer_.end(), '\\', ' ');
        return buffer_;
      } ();
const std::vector buffer=[&in](){
std::vector buffer_{std::istreambuf_迭代器(in),
std::istreambuf_迭代器()};
替换(缓冲区开始(),缓冲区结束(),'\n','';
std::replace(buffer\.begin()、buffer\.end()、'\\'、'';
返回缓冲区;
} ();

你能帮我写一封信吗?请发帖。这无法在gcc中编译,因为未捕获
中的
变量<代码>缓冲区
是最麻烦的解析。你从哪里看到与Rcpp的关系?你看过标签说明了吗?我删除了
rcpp
标签。