1
#include<iostream>
#include<fstream>

int main()
{

std::string folderPath("./");

std::string fileFoo = folderPath + "";
std::string fileBar = folderPath + "nonexisting_file"; 

std::ifstream foo(fileFoo.c_str());
std::ifstream bar(fileBar.c_str());

std::cout << foo.good() << std::endl;
std::cout << bar.good() << std::endl;

}

出力:

1
0
  1. ストリーム ファイル パスがディレクトリであるとはどういう意味ですか。
  2. fstreamこの場合、読み取り可能であることを確認する方法good()は機能しないためです。

編集

これは関連しているようです:

プラットフォーム: Linux (Ubuntu 12.04)

4

1 に答える 1

2

ファイル システムによっては、ディレクトリ一種のファイルであり、あまり変わらない場合がよくあります。また、サードパーティのライブラリを使用しない限り、やろうとしていることの処理はプラットフォームに依存しないため、 を使用することを強くお勧めしboost::filesystemます。

于 2013-04-24T15:51:20.663 に答える