2013-10-30 53 views
1

每次我嘗試建立這個代碼我得到一個錯誤,調用getline()沒有匹配的函數嗎?

「爲號召函數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; 
} 

回答

5

第三個參數是一個字符,所以你需要

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

注單引號。 "*"是一個以NULL結尾的字符串文字,類型爲const char[2]

+0

你,我的朋友,是最偉大的人類活着。謝謝!哈哈我會檢查標記答案一旦這個小小的11分鐘限制的事情用完了。非常感謝你! –