Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 是否可以在C+;中创建隐藏的txt文件+;?_C++_Windows_Visual Studio - Fatal编程技术网

C++ 是否可以在C+;中创建隐藏的txt文件+;?

C++ 是否可以在C+;中创建隐藏的txt文件+;?,c++,windows,visual-studio,C++,Windows,Visual Studio,我正在Visual Studio中构建一个应用程序。我需要创建一些要在dll中使用的文件,但我希望在查看文件夹时隐藏这些文件。如何在C++程序中实现这一点? 以交互方式,您可以通过右键单击文件,选择“属性”并选择“隐藏”来标记文件已隐藏。问题是,如何在C++中使用与C++程序等价的东西?使用Windows API中的函数: #include <windows.h> #include <fstream> std::fstream file; int main(){

我正在Visual Studio中构建一个应用程序。我需要创建一些要在dll中使用的文件,但我希望在查看文件夹时隐藏这些文件。如何在C++程序中实现这一点? 以交互方式,您可以通过右键单击文件,选择“属性”并选择“隐藏”来标记文件已隐藏。问题是,如何在C++中使用与C++程序等价的东西?

使用Windows API中的函数:

#include <windows.h>
#include <fstream>

std::fstream file; 
int main(){ 

   file.open("myUnhiddenFile.txt",std::ios::out); 
   file << "This is my unhidden file, that I have created just now" ; 
   file.close();

   wchar_t* fileLPCWSTR = L"myUnhiddenFile.txt"; // To avoid incompatibility
                                                 // in GetFileAttributes()
   int attr = GetFileAttributes(fileLPCWSTR);
   if ((attr & FILE_ATTRIBUTE_HIDDEN) == 0) {
       SetFileAttributes(fileLPCWSTR, attr | FILE_ATTRIBUTE_HIDDEN);
    }
   return(0);
} 
#包括
#包括
std::fstream文件;
int main(){
打开(“myUnhiddenFile.txt”,std::ios::out);
文件使用Windows API中的函数:

#include <windows.h>
#include <fstream>

std::fstream file; 
int main(){ 

   file.open("myUnhiddenFile.txt",std::ios::out); 
   file << "This is my unhidden file, that I have created just now" ; 
   file.close();

   wchar_t* fileLPCWSTR = L"myUnhiddenFile.txt"; // To avoid incompatibility
                                                 // in GetFileAttributes()
   int attr = GetFileAttributes(fileLPCWSTR);
   if ((attr & FILE_ATTRIBUTE_HIDDEN) == 0) {
       SetFileAttributes(fileLPCWSTR, attr | FILE_ATTRIBUTE_HIDDEN);
    }
   return(0);
} 
#包括
#包括
std::fstream文件;
int main(){
打开(“myUnhiddenFile.txt”,std::ios::out);
文件
#包括
DWORD attributes=GetFileAttributes(“MyFile.txt”);
SetFileAttributes(“MyFile.txt”,属性+文件属性\u隐藏)
#包括
DWORD attributes=GetFileAttributes(“MyFile.txt”);
SetFileAttributes(“MyFile.txt”,属性+文件属性\u隐藏)

选中“”复选框时,可以很容易地看到使用FILE_属性_HIDDEN创建的文件。真正隐藏文件的唯一方法是使用将在调用()时从结果中删除文件(或文件/s模式)记录的。Windows文件资源管理器调用NtQueryDirectoryFile()因此,使用这种驱动程序,即使选中了“隐藏项”,文件也不会显示


选中“”复选框时,可以很容易地看到使用文件属性\u HIDDEN创建的文件。真正隐藏文件的唯一方法是使用将在调用()时从结果中删除文件(或文件/s模式)记录的。Windows文件资源管理器调用NtQueryDirectoryFile()因此,使用这种驱动程序,即使选中了“隐藏项”,文件也不会显示


试试这个简单的技巧

#include<iostream>
using namespace std;

int main(){
system("echo >file.txt");
system("attrib +h +s file.txt");

return 0;
}
#包括
使用名称空间std;
int main(){
系统(“echo>file.txt”);
系统(“attrib+h+s file.txt”);
返回0;
}

试试这个简单的技巧

#include<iostream>
using namespace std;

int main(){
system("echo >file.txt");
system("attrib +h +s file.txt");

return 0;
}
#包括
使用名称空间std;
int main(){
系统(“echo>file.txt”);
系统(“attrib+h+s file.txt”);
返回0;
}

当你在文件中按下鼠标右键时,出现一个菜单,你选择属性并显示文件的属性窗口,你在“ATTIUBUTTES”中可以选择“只读”或“隐藏”(这是我想要的)。没有可移植的方法来创建隐藏文件,无论是在C还是C++中。“隐藏文件”是Windows特有的特性。你必须使用一些Windows特定的代码来标记一个隐藏的文件。C或C++。它们是两种不同的语言。听起来好像你在使用C++,所以就坚持下去。(答案可能和C一样,但是没有什么东西可以混淆。)(实际从事Windows编程的人可以自由地将其纳入回答中)隐藏是什么意思?当您在文件中按鼠标右键时,会出现一个菜单,您选择属性并显示文件属性窗口,您可以在“属性”中选择“只读”或“隐藏”(这是我想要的)在C或C++中没有隐藏的方法来创建隐藏文件。“隐藏文件”是一个Windows特定的特性。你必须使用一些Windows特定的代码来标记一个隐藏的文件。C或C++。它们是两种不同的语言。听起来好像你在使用C++,所以坚持下去。(答案可能恰好与C中的答案相同,但没有必要混淆。)(真正从事Windows编程的人应该可以随意将其纳入答案中)您忘记了
#include
s和
const
@LightnessRacesinOrbit我没有忘记:-)我不知道应该包括哪一个:-)因此,如果您能提供帮助,我将不胜感激:-)我假设
来自
windows。h
不提供
std::fstream
。停止猜测并阅读文档!!!!!我假设Alex知道这一点,只是不熟悉windows api。您忘记了
\include
s和
const
@LightnessRacesinOrbit我没有忘记:-)我不知道我应该包括哪一个:-)所以如果你能帮助我,我会非常感激:-)我会假设
来自
windows。h
不提供
std::fstream
。停止猜测并阅读文档!我假设Alex知道那一个,只是不熟悉它e windows api。