简体   繁体   English

编译错误 - 多个构造函数实例 "std::basic_string<_Elem, _Traits, _Alloc>::basic_string

[英]Compilation error - more than one instance of constructor "std::basic_string<_Elem, _Traits, _Alloc>::basic_string

I am new in C++ language, and I am trying to follow an example I found online.我是 C++ 语言的新手,我正在尝试按照我在网上找到的示例进行操作。 I am copying-pasting the online code line by line and trying to build after adding each line (because I am sure that it would never compile if I copy-pasted the whole code:)我正在逐行复制粘贴在线代码并在添加每一行后尝试构建(因为我确信如果我复制粘贴整个代码它永远不会编译:)

I am facing the below errors:我面临以下错误:

E0309 more than one instance of constructor "std::basic_string<_Elem, _Traits, _Alloc>::basic_string [with _Elem=char, _Traits=std::char_traits, _Alloc=std::allocator]" matches the argument list E0309 构造函数“std::basic_string<_Elem, _Traits, _Alloc>::basic_string [with _Elem=char, _Traits=std::char_traits, _Alloc=std::allocator]”的多个实例匹配参数列表

C2668 'std::basic_string<char,std::char_traits,std::allocator>::basic_string': ambiguous call to overloaded function C2668 'std::basic_string<char,std::char_traits,std::allocator>::basic_string':对重载 function 的模糊调用

My code is:我的代码是:

#include <iostream>
#include <limits>
#include <fstream>
#include <string>

#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>

int main()
{
    using namespace std;
    string filename(0, MAX_PATH);  // <------- This is the line which throws the error

    std::cout << "Hello World!\n";

    std::cout << "Press ENTER to continue...";
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}

Just in case someone else faced the same issue (highly unlikely), the correct syntax for this line is:以防其他人遇到同样的问题(极不可能),此行的正确语法是:

string filename(MAX_PATH, '\0');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 编译错误提示&#39;std :: basic_string <charT, _Traits, _Alloc> - Compiling error that says 'std::basic_string<charT, _Traits, _Alloc> C ++类型转换:错误C2440:“正在初始化”:无法从“ HRESULT”转换为“ std :: basic_string &lt;_Elem,_Traits,_Alloc&gt;” - c++ type conversion: error C2440: 'initializing' : cannot convert from 'HRESULT' to 'std::basic_string<_Elem,_Traits,_Alloc>' 错误C2664:无法将参数1从&#39;const std :: basic_string &lt;_Elem,_Traits,_Ax&gt;&#39;转换为&#39;std :: wstring& - error C2664: cannot convert parameter 1 from 'const std::basic_string<_Elem,_Traits,_Ax>' to 'std::wstring & 无法将参数1从&#39;char&#39;转换为&#39;const std :: basic_string &lt;_Elem,_Traits,_Ax&gt;&&#39; - cannot convert parameter 1 from 'char' to 'const std::basic_string<_Elem,_Traits,_Ax> &' 无法将参数1从&#39;CHAR [260]&#39;转换为&#39;const std :: basic_string &lt;_Elem,_Traits,_Ax&gt; - cannot convert parameter 1 from 'CHAR [260]' to 'const std::basic_string<_Elem,_Traits,_Ax> std :: basic_string的使用 - Uses of std::basic_string basic_string类确实具有带多个参数的复制构造函数,还是仅仅是构造函数? - Does basic_string class really have copy constructor that takes more than one parameter or is it just constructor? std::basic_string 特化 - std::basic_string specialization C++ std::basic_string/char_traits 特化 - C++ std::basic_string/char_traits specialization 错误:地图中的operator =含糊不清的重载 <int, std::basic_string<char> &gt; :: Elem :: t3 = 0 - error: ambiguous overload for operator= in Map<int, std::basic_string<char> >::Elem::t3 = 0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM