簡體   English   中英

C++:如何在使用 getline() 的兩個重載時重新定義它?

[英]C++: how to redefine getline() when using two overloads of it?

我需要在我的程序中使用兩種類型的 getline。
第一的:

template<> std::istream &std::getline<char, std::char_traits<char>, std::allocator<char>>(std::istream &__is, std::__cxx11::string &__str, char __delim)
+4 overloads

Read a line from an rvalue stream into a string.

我在一段時間內使用它。

getline(strstrm, field,',')

在哪里:

string line, field, temp;
stringstream strstrm(line);

但是現在當我嘗試使用這個 getline 時:

getline(rowTemp, lineTemp);

我得到一個錯誤。 這里:

string lineTemp, wordTemp;
vector<string> rowTemp;

我已經添加了聲明:

using namespace std;

我正在使用以下 header 文件

#include<iostream>
#include<string>
#include<limits>
#include<fstream>
#include<iomanip>
#include<conio.h>
#include<vector>
#include<algorithm>

我的錯誤是

getline
+6 overloads

Read a line from stream into a string.

Parameters:
__is – Input stream.
__str – Buffer to store into.

Returns:
Reference to the input stream. Stores characters from is into __str until '

no instance of overloaded function "getline" matches the argument list -- argument types are: (std::vector<std::__cxx11::string, std::allocator<std::__cxx11::string>>, std::__cxx11::string)C/C++(304)

我的整個代碼可以在這里看到

我對 c++ 有點陌生。 如果有人能指出我正確的方向,我將不勝感激。 謝謝你。

我誤寫了這個

getline(rowTemp, lineTemp);

代替

getline(accounts, lineTemp);

帳戶是:

fstream accounts;

謝謝@Jarod24 的最小曝光,因為我回去查看了我的代碼並得到了錯誤。 無論如何感謝任何人的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM