难以通过ifstream在C 中找到文件
trouble finding file in c++ via ifstream
我已经尝试了5次此程序,但仍然无法找到我提供的路径的文件。我如何指定文件路径
#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
ifstream infile("C:\UsersDellDocumentsVisual Studio 2017TemplatesProjectTemplatesVisual C++ Projecty.txt");
char a[20];
if (!infile)
cout<<"file doesnt exists";
else
while (infile.getline(a, 20, '/n'))
{
cout << a;
}
_getche();
}
基本上如何指定文件路径
您必须逃脱文件路径中出现的所有后斜线,不仅是第一个:
ifstream infile("C:\Users\Dell\Documents\Visual Studio 2017\Templates\ProjectTemplates\Visual C++ Project\y.txt");
// ^ ^ ^ ^ ...
另一种方法是使用原始字符串文字:
ifstream infile(R"(C:UsersDellDocumentsVisual Studio 2017TemplatesProjectTemplatesVisual C++ Projecty.txt)");
相关文章:
- ifstream文件在从行中读取时被清除
- 是否可以在没有真实文件的情况下创建 ifstream
- 虽然循环不读取整个 ifstream 文件
- std::ifstream 在读取文件中最后一项时设置 eofbit,但仅在读取数值类型时发生
- C++:std::ofstream 方法 open() 在第二次迭代时擦除打开的 ifstream 文件
- ifstream 读取的字符与文件中写入的字符不同
- 如何使用 ifstream 检查文件中变量的类型?
- 尝试使用 Ifstream 打开.txt文件时C++问题
- ifstream不会在下一次迭代中打开文件
- 当文件位于正确位置时,ifstream无法打开该文件
- 使用ifstream时,被调用文件中的数据不会打印
- 从带有 std::ifstream::read() 的文件中读取 int 遍历 char * 二进制数据
- 如何确保我的"ifstream"文件对象指向的文件内容已更新?
- ifstream说它打开了一个文件,但文件没有打开
- VS Express 2015 Win10 应用程序 - ifstream 无法打开文件
- C++ : 如何在使用 getline() 和 ifstream 对象从文件中读取一行时跳过第一个空格?
- C++如何附加ifstream以将多个文件读取为一个大文件
- 尝试在c++中将文本文件(ifstream)转换为2D字符数组
- 读取文件(ifstream)和写入文件(ofstream)-编码问题
- 如何共享文件删除权限时,我打开一个文件ifstream