1、如何将一个文本文件拷贝到一个字符串中?
ifstream inputFile("interestingData.txt"); string fileData((istream_iterator<char>(inputFile)),istream_iterator<char>());
这虽然是一个可行的方法,但是不建议使用,因为这样会把文件中所有的空格忽略
建议使用:
ifstream inputFile("interestingData.txt"); string fileData((istreambuf_iterator<char>(inputFile)),istreambuf_iterator<char>());相关函数:
string cook;1、cook.c_str()它返回当前字符串的首字符地址.c_str函数的返回值是constchar*的,不能直接赋值给char*.