C++ C++;使用字符数组的getline错误

C++ C++;使用字符数组的getline错误,c++,C++,我一直收到一个错误,在getline(输入,句子)上说“error:no matching function for call to'getline(std::ifstream&,char[100])”|。我不确定我可能错过了什么。我要做的是从输入中读取整行内容,并使用getline将其插入char语句[100]。我必须按照作业要求使用getline。先谢谢你 char uniqueWords[100][16] = {""}; int multipleWords = 0; i

我一直收到一个错误,在getline(输入,句子)上说“error:no matching function for call to'getline(std::ifstream&,char[100])”|。我不确定我可能错过了什么。我要做的是从输入中读取整行内容,并使用getline将其插入char语句[100]。我必须按照作业要求使用getline。先谢谢你

char uniqueWords[100][16] = {""};
int multipleWords = 0;
int theWords[100];
int totalWords = 0;
char sentence[100];
char delimit[] = " /.";


ifstream Input;
Input.open("input.txt");
if (!Input.is_open())
{
    cout << "Error Opening File";
    exit(EXIT_FAILURE);
}

ofstream Output;
Output.open("output.txt", std::ios_base::app);
if (!Output.is_open())
{
    cout << "Error Opening File";
    exit(EXIT_FAILURE);
}


char *p;

while(!Input.eof())
{
    getline(Input, sentence);
    p = strtok(sentence, delimit);
    while(p)
    {
        Output << p ;
        words(p, uniqueWords, theWords, multipleWords);   // a function for the assignment
        totalWords++;
        p = strtok(nullptr,delimit);
    }
    create << "." << endl;
}
char uniqueWords[100][16]={''};
整数倍数=0;
输入单词[100];
整数totalWords=0;
char语句[100];
字符分隔符[]=“/”;
ifstream输入;
Input.open(“Input.txt”);
如果(!Input.is_open())
{

cout问题是您试图使用而不是(例如,您使用的
getline()
)错误的
getline())
您尝试使用的目标存储需要一个
std::string
,而不是一个普通的旧字符数组。上面的第二种形式是一个字符数组及其大小。您可以使用:

    while (Input.getline(sentence, sizeof sentence))
    {
        p = strtok (sentence, delimit);
        while (p)
        {
            Output << p ;
            words (p, uniqueWords, theWords, multipleWords);   // a function for the assignment
            totalWords++;
            p = strtok(nullptr,delimit);
        }
        std::cout << ".\n";
    }
除此之外,您应该真正使用
std::string
存储字符串,并使用
std::vector
存储字符串集合。您可以将每个字符串复制到字符数组中,以便使用
strtok()
进行解析。请仔细查看,如果您还有其他问题,请告诉我。

当然。
getline(stream,std::string)
std::string
为参数。您想要
stream.getline(字符数组,大小)
(例如
Input.getline(句子,句子大小)
)为什么要使用字符数组而不是
std::string
std::vector>
作为存储?另请参见
    std::ifstream Input ("input.txt");
    if (!Input.is_open())
    {
        std::cerr << "Error Opening File.\n";
        exit (EXIT_FAILURE);
    }