![](/img/trans.png)
[英]C++, passing filename in string to class function using it for ifstream object
[英]Error on filename creating Ifstream object
失敗的任何特定原因?
std::string r = "Hej.whatever";
std::string const *p = &r;
std::ifstream file ((*p).c_str(), std::ios::in, std::ios::ate);
std::ifstream file ((*p), std::ios::in, std::ios::ate);
error: no matching function for call to
‘std::basic_ifstream<char>::basic_ifstream(const string&,
const openmode&, const openmode&)’
std::ifstream file ((*p), std::ios::in, std::ios::ate);
您需要按位OR( |
)傳遞幾種模式:
std::ifstream file ((*p), std::ios::in | std::ios::ate);
std::ifstream file2 ((*p), std::ios::in | std::ios::ate);
您可以從第一次調用中刪除.c_str()
,而無需使用它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.