[英]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.