获取文件的一部分
c++ Getting a portion of a file
如何跳过文件的某些部分,然后跳过ifstream
,直到到达某个字符?
例如,在文本文件中,这样写:
'SaveNameExample'
variableExample = 5;
我如何只得到没有'
s的SaveNameExample,将其存储为std::string
变量,然后仅从下一行获得5,以保存为int
变量?
按照下面这些行应该可以工作:
string s = "";
char c = '';
int i = 0;
while(getline(fstream_name, temp)){
for(int i = 0; i < temp.length(); i++){
if(temp[i] != "'")
s += temp[i];
if(temp[i] >= x || temp[i] <= y) //Where x and y are ascii values for 0 and 9, respectively
c = temp[i];
}
}
i = atoi(c);
这只会在某些情况下起作用,但你应该能够操纵它来适应你想要做的。
相关文章:
- 如何检测文件夹是否太重,如果是,请删除其中的一部分
- 如何将文件的一部分读取到std::list缓冲区?
- 链接库作为 CMAKE 中工具链文件中标志的一部分
- 是否可以使用 GCC 编译具有特定编译器标志的代码文件的一部分?
- 按文件中列表中行的一部分排序
- qfile qtextStream仅读取文件的一部分
- 如何在C++中删除文件中的一部分文本
- C 如何将二进制文件的一部分复制到新文件
- Qml:从文件加载组件时将参数作为 URL 的一部分传递
- Eclipse-cdt boost shared_ptr.hpp:目录中没有此类文件,但它的一部分是包含文件
- 只读二进制zip文件的一部分
- c++为类和.cpp文件分离文件,函数不是类的一部分
- 复制存储在内存映射文件中的数组的一部分
- 如何在C 中获取.CSV文件的一部分
- 如何在C 中获取文本文件的一部分
- 使用输入作为名称的一部分创建文本文件
- 在c++中读取一行.txt文件的一部分
- 将二进制文件的一部分读入预先存在的basic_string对象
- C++ *char 缓冲区的一部分写入 Windows 上的临时文件
- 使用C++当我同时具有整数和字符数组时,如何将.txt文件中的数据作为链表的一部分访问