无法打开文件n C ++ [英] Unable to open file n C++

查看:148
本文介绍了无法打开文件n C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


我正在尝试用c ++编写/读取文件。写入文件的函数如下:



hi
I'm trying to write/read from a file in c++. The function which writes to a file is as follows:

const char * EncQR = Extract_ClientPublicKey_Encrypt_QRcode(str, ClientCert_String);

ofstream myfile1;
myfile1.open("ram.txt");
if (myfile1.is_open())
  {
	   myfile1 <<EncQR<<"\n";
  }
else
   cout<<"Unable to open file";





前面的代码工作正常,并写入txt文件。但问题在于下一个函数,它尝试从文件中读取:





The previous code works fine, and write into a txt file. But the problem is with the next function, which tries to read from a file:

int _tmain(int argc, _TCHAR* argv[])
{
   string line;
  // reading a text file
  ifstream myfile1("ram.txt");
  if (myfile1.is_open())
  {
   while(! myfile1.eof()) {
			getline(myfile1, line);
			std::cout << line << "\n\n";}
  }

  else cout << "Unable to open file";
  getch();
  myfile1.close();
  return 0;
}



我不断收到无法打开文件。我尝试过另一个由一行组成的文件,它正在运行。但是使用ram.txt文件,它由多行组成,它不起作用。

我甚至试图将文件复制到我的项目所在的目录中,而且,没有工作。



需要帮助pleeeeease



问候。


Where i keep getting "Unable to open file". I've tried another file consisting of a single line, and it was working. but with the "ram.txt" file, which consists of multiple lines, it doesn't work.
I even tried to copy the file into the directory in which my project is located, and still, didnt work.

Need help pleeeeease

Regards.

推荐答案

正在创建的文件在哪里?



您可以尝试:



打开(。\\ram.txt)
两个函数的


。我想你会觉得它有用。



马特
Where is the file being created?

You might try:

open(".\\ram.txt")

for both functions. I think you'll find it works.

Matt


这篇关于无法打开文件n C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆