C++ : ifstreamObject.getline(c string, char limit) 中的动态 C 字符
C++ : Dynamic C-String Usage in ifstreamObject.getline(c string, char limit)
我想知道在使用 getline 方法时,是否有办法将空间动态分配给字符 aray,等于文件中行中的空格量。(C++)
例
int main(){
char *theLine;
ifstream theFile;
//set theLine = new char[sizeOftheFileLine]
//is there a way do the above
theFile.getline(theLine, 500);
return 0;
}
如果使用 std::getline
,则会获得所需的行为。
std::string theLine;
std::ifstream theFile;
// ....
std::getline(theFile, theLine);
相关文章:
- std::向量与传递值的动态数组
- 在c++中用vector填充一个简单的动态数组
- C++中的动态铸造故障
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 内联映射初始化的动态atexit析构函数崩溃
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- 控制允许动态运行c++的并发操作数
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 在调用FreeLibrary后,释放动态链接到具有相同版本的CRT堆的DLL的内存
- 输出没有重复元素的动态数组(收缩数组)C++
- C++为线程工作动态地分割例程
- 正在插入动态数组
- 在c++中使用动态分配的问题
- C++中的动态对象与非动态对象
- 如何在动态数组上使用搜索函数
- 视觉studo 2019中的漫画和静态/动态绑定
- 从C++中的数字输入动态创建矩阵
- 如何从QToolBox中动态创建的QLineEdit中获取文本
- C++ 动态数组每次添加时将大小增加 1 - 错误
- C++ : ifstreamObject.getline(c string, char limit) 中的动态 C 字符