您的位置:首页 > 其它

string类、字符串数组相关问题

2015-01-13 22:03 183 查看
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*.

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: