如何使用system()打开.txt; [英] how do open a .txt using system();

查看:221
本文介绍了如何使用system()打开.txt;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说.cpp文件中有一个code.txt



lets say that there is a code.txt with the .cpp file

#include<iostream>
#include<string>
#include<fstream>

using namespace std;

int main(){
string file;
cout <<"enter file name";
cin  >> file;
system(file);
}

is there an a way to open a txt file by using the user input. i only know for example system("code.txt"); but what if if it is user-defined. please help.

推荐答案

试试吧。

如果code.txt有效,那么如果是用户输入code.txt它会做同样的事情。

如果用户输入D:\ Temp \DeleteMyHardDiskPlease.exe,那么系统将查找该名称的可执行文件位置并尝试运行它。所以...我要小心你让用户输入...
Try it.
If "code.txt" works, then if the user enters "code.txt" it will do the same thing.
If the user enters "D:\Temp\DeleteMyHardDiskPlease.exe" then the system will look for an executable of that name in that location and try to run it. So...I'd be careful what you let the user enter...


这篇关于如何使用system()打开.txt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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