c++ - 关于 LoadVector 语法的说明(将 txt 文件转换为向量)
问题描述
我正在做一个项目,但在使用 Loadvector 语法时遇到了问题。到目前为止我有这个
/* ----------------------------------------- */
/* --------------LoadVector ---------------- */
/* ----------------------------------------- */
vector <int> LoadVector(string filename) {
vector <int> c;
cout << "Open the file" << endl;
ifstream cf(filename);
// test file open
if (cf.is_open()) {
int value;
// read the elements in the file into a vector
while (cf >> value) c.push_back(value);
// close the file
cout << "Close the file" << endl;
cf.close();
}
else {
cout << "File not found" <<endl;
}
return c;
}
当我尝试构建它时,我得到“打开文件未找到文件”
这些文件是一系列数字,我将它们作为 .txt 文档保存在项目文件夹中。我认为我在程序指向获取文件的地方遗漏了一些东西。任何建议将不胜感激。
谢谢!
解决方案
推荐阅读
- flutter - 如何从 carousel_pro 颤振中传输图像的 ID
- java - MSSQL:为什么在我更新实体后 findAll 不起作用 - Spring Boot JPA
- ssh-keygen - ssh-keygen -l -f 文件因 dsa 密钥内容而失败
- javascript - 未捕获的语法错误:无法在模块 Vue 3 PWA Workbox 之外使用导入语句
- android - 为什么我们需要为 DataBinding 和 LiveData 扩展 ```ViewModel()``` 来创建 LiveData 对象
- apache-spark - Spark - 我无法在本地模式下增加任务数量
- android - Android 应用程序布局在相同宽高比设备上显示不同
- ubuntu - 在 Linux-ARM64 上的 GUI 中显示 /dev/videoX 提要
- python - 带有输入 csv 和输出表以及绘图 png 文件的 GUI
- python - 正则表达式中缺少某些内容?