如何在C++中的字符串数组中找到下一个空闲元素,然后将数据附加到它
How would I find the next free element in a string array in C++ then append data to it?
Exzample代码。。。
const int SIZEOFFILENAMES = 100;
string fileNames[SIZEOFFILENAMES];
int main () {
string inFilePath;
cout << "Specify the file path:" << endl;
cin >> inFilePath;
ifstream inFile;
// open in binary
inFile.open(inFilePath.c_str(), ios::binary);
inFile.seekg(0, ios_base::end);
int fileLen = inFile.tellg();
inFile.seekg(0, ios_base::beg);
char charArr[10000];
inFile.read(charArr, fileLen);
inFile.close();
inFile.clear(ios_base::goodbit);
比索代码应该是
检查filename数组元素大小。
将inFilePath附加到下一个自由元素。
}
下面是一个将输入的文件路径添加到文件名向量的简单示例:
// ...
#include <vector>
#include <string>
std::vector<std::string> fileNames;
int main ()
{
std::string inFilePath;
std::cout << "Specify the file path:" << std::endl;
std::cin >> inFilePath;
filenames.push_back(inFilePath);
// do other stuff
// ...
}
相关文章:
- 如何为 std::vector 分配内存,然后稍后为某些元素调用构造函数?
- 有没有办法搜索向量的元素,<String>然后检查它是否包含特定的字符,如果它确实打印了它
- 如何在类中制作 2D 数组元素,然后在其构造函数中指定其维度?
- 将集合的随机元素添加到列表中,然后将其从原始集合中移除
- 将函数应用于元组中的每个元素,将每个元素强制转换为类型包中的不同类型,然后作为参数包传递
- 如何打印第一个和最后一个元素的和,然后打印第二个和倒数第二个元素的总和,依此类推
- 对数组进行排序的算法,先是第一个元素,然后是前 2 个元素,然后是前 3 个元素,依此类推
- 如何检查单向链表的每个 3 个元素,然后删除其中一些元素?
- 扫描阵列特定次数,然后找出元素
- 从地图上擦除元素,然后将其放回原处
- 如何在多维数组中搜索单个行,然后对某些行中的每个单个元素执行计算
- 如何将元素的索引从2D数组存储到1D数组中,然后交换这些值
- 如何使用 for 循环将元素加载到我的每个数组中,然后将每个数组的总和输出到一个 sum 数组中
- 如何将一个数组的每个元素与另一个元素进行比较(如果存在),然后打印是,否则否
- C++如何将结构数组初始化为null,然后在while循环中检查该数组的元素是否为null
- 将数组传递到空隙函数,然后递归打印元素
- 在2D向量中找到一个元素,然后将其删除
- 在数组中输入5个元素,检查验证,然后输出C++
- 创建结构元素的动态数组,然后创建该结构的动态数组.C++
- 在数组的元素中插入一个新值,然后移动其余元素