积极答复者
iostream ifstream 转化

问题
答案
-
请使用std::freopen。大概使用方法:
#ifndef _DEBUG std::freopen(R"(C:\test.txt)","w+",stdout); #endif
Visual Basic 初学者 望关照!
- 已编辑 LYP VB Learner 2015年1月12日 4:52
- 已标记为答案 Shu 2017 2015年1月16日 9:46
-
/* freopen example: redirecting stdout */ #include <stdio.h> int main () { freopen ("C:\\myfile.txt","w",stdout); printf ("This sentence is redirected to a file."); fclose (stdout); return 0; }
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已编辑 VisualElevenModerator 2015年1月12日 10:56
- 已标记为答案 Shu 2017 2015年1月16日 9:46
全部回复
-
您的意思是手动输入文件名,然后打开该文件读写数据吗?
类似下面这样的:
#include <iostream>
#include <fstream>
using namespace std;
....
char szPath[MAX_PATH] = {0};
cin >> szPath;
ifstream in(szPath, ifstream::xxx);
if(in)
{
....
in.close();
}
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
-
请使用std::freopen。大概使用方法:
#ifndef _DEBUG std::freopen(R"(C:\test.txt)","w+",stdout); #endif
Visual Basic 初学者 望关照!
- 已编辑 LYP VB Learner 2015年1月12日 4:52
- 已标记为答案 Shu 2017 2015年1月16日 9:46
-
/* freopen example: redirecting stdout */ #include <stdio.h> int main () { freopen ("C:\\myfile.txt","w",stdout); printf ("This sentence is redirected to a file."); fclose (stdout); return 0; }
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已编辑 VisualElevenModerator 2015年1月12日 10:56
- 已标记为答案 Shu 2017 2015年1月16日 9:46