错误"函数调用缺少参数列表" - 帮助指出我正确的方向

时间:2014-03-29 04:30:40

标签: c++

背景:尝试编写一个简单的程序,使用字符串在999以上的数字中添加逗号。

编译器:Visual Studio 2012

问题:我不明白错误意味着什么,我不知道在哪里搜索找到答案(我在网上找到的所有内容都是特定于所提供的代码)

结果:对错误的解释是试图告诉我或要研究的主题或领域。

代码:

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

using namespace std;




int _tmain(int argc, _TCHAR* argv[])
{
string value="1000";
int size = value.size();
switch (size) {
case 1:
    break;
case 2:
    break;
case 3:
    break;
case 4:
    value.resize(size+1);
    value.insert(value.begin+1,',');
        break;
default:
    cout << "I dont know how i got here??" << endl;
    break;
} // end of switch
return 0;
}

结果:

1>i:\programming\comma_placing_in_numbers\comma_placing_in_numbers\comma_placing_in_numbers.cpp(29): error C3867: 'std::basic_string<_Elem,_Traits,_Alloc>::begin': function call missing argument list; use '&std::basic_string<_Elem,_Traits,_Alloc>::begin' to create a pointer to member
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Alloc=std::allocator<char>
1>          ]
1>i:\programming\comma_placing_in_numbers\comma_placing_in_numbers\comma_placing_in_numbers.cpp(29): error C2664: 'std::basic_string<_Elem,_Traits,_Alloc> &std::basic_string<_Elem,_Traits,_Alloc>::insert(unsigned int,const std::basic_string<_Elem,_Traits,_Alloc> &)' : cannot convert parameter 2 from 'char' to 'const std::basic_string<_Elem,_Traits,_Alloc> &'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Alloc=std::allocator<char>
1>          ]
1>          Reason: cannot convert from 'char' to 'const std::basic_string<_Elem,_Traits,_Alloc>'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Alloc=std::allocator<char>
1>          ]
1>          No constructor could take the source type, or constructor overload resolution was ambiguous

1 个答案:

答案 0 :(得分:2)

编译器很好地解释了它。

value.insert(value.begin+1,',');

begin是一个功能。它需要调用带括号的列表符号()