문제

someone just helped me get a filename from a directory with boost using

    if (exists(p))    // does p actually exist?
    {

        if (is_directory(p))      // is p a directory?
        {
            copy(directory_iterator(p), directory_iterator(), // directory_iterator::value_type
                ostream_iterator<directory_entry>(cout, "\n")); // is directory_entry, which is

        }
    }

but I want it in a string not cout

how can i capture that copy?

도움이 되었습니까?

해결책

You can copy the content to a std::ostringstream and retrieve a copy of the buffer using str():

std::ostringstream buf;

std::copy(directory_iterator(p), directory_iterator(),
          std::ostream_iterator<directory_entry>(buf, "\n"));

std::string content(buf.str());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top