注册 登录
编程论坛 C++教室

编程错误

醒山 发布于 2015-11-06 20:38, 584 次点击
编程错误提示如下:错误    1    error C2664: “std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::get(std::basic_streambuf<char,std::char_traits<char>> &,_Elem)”: 无法将参数 1 从“char”转换为“char *”    c:\users\think\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp    10    1    ConsoleApplication1
错误    2    error C2664: “void strcount(const char *)”: 无法将参数 1 从“char”转换为“const char *”    c:\users\think\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp    16    1    ConsoleApplication1
    4    IntelliSense:  没有与参数列表匹配的 重载函数 "std::basic_istream<_Elem, _Traits>::get [其中 _Elem=char, _Traits=std::char_traits<char>]" 实例
            参数类型为:  (char, const int)
            对象类型是:  std::istream    c:\Users\THINK\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp    10    5    ConsoleApplication1
应该怎么改??大家帮忙看看
#include<iostream>
const int ArSize = 10;
void strcount(const char * str);
int main()
{
    using namespace std;
    char input(ArSize);
    char next;
    cout << "Enter a line:\n";
    cin.get(input, ArSize);
    while (cin)
    {
        cin.get(next);
        while (next != '\n')
            cin.get(next);
        strcount(input);
        cout << "Enter next line (empty line to quit):\n";
        cin.get(input, ArSize);
    }
    cout << "Bye\n";
    return 0;
}
void strcount(const char * str)
{
    using namespace std;
    static int total = 0;
    int count = 0;
    cout << "\"" << str << "\"contains";
    while (*str++)
        count++;
    total += count;
    cout << count << " characters\n";
    cout << total << " characters total\n";
}
5 回复
#2
TonyDeng2015-11-06 21:35
input的char,而strcount()函數要求的參數是const char*,你自己看看調用類型對不對?再説了,你創建的是C++/CLI項目,卻全是本地C++模式。
#3
wp2319572015-11-10 13:09
进来看看
#4
醒山2015-11-11 20:10
本地c++模式?
#5
TonyDeng2015-11-12 03:11
vc++有兩種程序模式,一是傳統的本地代碼C++,另一是托管代碼C++,後者即基於.net的C++/CLI程序。從你創建的項目名稱ConsoleApplication看,這是C++/CLI項目,亦即你選了CLR模板。C++/CLI使用.net的類庫,其庫函數形式與C#、是一致的,因爲所有.net的程序,到最後的可執行程序,實際上沒有區別,反匯編是分不出原本用什麽語言寫的。本地C++代碼,又稱非托管代碼。
#6
rjsp2015-11-12 08:22
char input(ArSize); 改为 char input[ArSize];
1