gpt4 book ai didi

c++ - 没有匹配函数调用 getline()?

转载 作者:行者123 更新时间:2023-11-30 01:20:13 24 4
gpt4 key购买 nike

每次我尝试构建这段代码时都会出错,

"No matching function for call to getline()"

但我以前用过它并且效果很好? S 我不确定发生了什么。如果可以的话,我正在使用 Mavericks OSX,并使用 Xcode 来构建这个项目。是给学校的我知道 inputFile 工作正常,因为我已经评论了打印到控制台的 getline() 和“打开”。

//
// main.cpp
// Project 4
//
// Created by Eric Diviney on 10/27/13.
// Copyright (c) 2013 Eric Diviney. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
/*
|
|-------------------------------------------------------------
| Documentation
|-------------------------------------------------------------
| The headings[] array will contain all strings for the customer's receipt.
| the 2nd level of headings[][] will contain all of the info (name, address etc.) while
| the first level of headings[] will contain the number of customers. The order of the second level is heading1, heading2, customername,
| address, phone, footer
|
| The charges[] array will contain all double/floats required to compute the charges for the customer.
| The third level of charges[][][] will contain the actual charges/prices while the first level
| will hold n amount of customers. The second level of that array (charges[][]) will hold the first, second and third month.
| The order of the last array is electricity, water, and gas
|
| The output[] array is 3 customers in the first level (output[]) and the correspnding strings for each
| segment of their receipt output[][]. The order in the second level of this array is heading1, heading2, customerName, Customer address,
| customer Phone, Customer ID, electricity, water, gas, subtotal, discountRate, taxRate, tax for order, discount for order, order total,
| footer
|
*/

// variable declarations
string headings[3][7];
double charges[3][3][3];
string output[3][16];

ifstream inputFile;
inputFile.open("/Users/ericdiviney/Documents/workspace/project4/project4/input.txt");
if(inputFile.is_open())
{
cout << "Open" << endl;
}

getline(inputFile, headings[0][0], "*");
//cout << headings[0][0];

return 0;
}

最佳答案

第三个参数是单个字符,所以需要

getline(inputFile, headings[0][0], '*');

注意单引号。 "*" 是一个以 null 结尾的字符串文字,类型为 const char[2]

关于c++ - 没有匹配函数调用 getline()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19695304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com