- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在编写一个管理主机文件条目的应用程序。所以我用 C++ 编写了一些代码来尝试访问和读取 HOSTS 文件:
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
int main(void)
{
string line;
fstream f ("C:\Windows\System32\drivers\etc\hosts");
if ( f.is_open() )
{
while ( f.good() )
{
getline(f,line);
cout << line << endl;
}
f.close();
} else
cout << "Error" << endl;
system("pause");
return 0;
}
在提出这个问题之前,我读过这个:edit the etc\hosts file
所以,是的,我试过以管理员身份运行该程序,但它仍然不起作用。我的程序如何读取/编辑以管理员身份运行的主机?
最佳答案
在 C++ 中,您必须在字符串文字中引用 反斜杠。所以尝试:
fstream f ("C:\\Windows\\System32\\drivers\\etc\\hosts");
这是因为使用像 \n
这样的单个反斜杠对编译器来说意味着一些特殊的东西。
关于c++ - 在 Windows 上编辑 HOSTS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8017922/
Windows“主机”文件编码是什么?是UTF-8吗?还是 ASCII + 系统代码页?应如何添加 IDN(带有变音符号等的国际域名)条目以及它们是否可以添加? 最佳答案 它应该是没有 BOM 的 A
我已经在谷歌上搜索了大约 90 分钟,但仍然没有答案。在哪里设置 default_url_options?我已经将其设置为 config.action_mailer.default_url_optio
我正在从它的样式文件中设计一个 Angular 组件,我发现我必须使用 :host ,:host() 或 :host-context selector ,它们各自有什么不同? 最佳答案 :主机 是用于
我正在创建简单的网络应用程序。而且我在服务器配置方面遇到了问题。当我尝试启动服务器时,收到错误消息 The element type "Host"must be terminated by the m
这个有效: 127.0.0.1 www.somesite.com 但不是这个: 127.0.0.1/somepath/www www.mysite.com 我做错了什么?是否可
我必须查看我的前同事留下的一些脚本,我很好奇为什么他在参数中使用 $a = $(Read-Host -Prompt "Write Something")节而不是 $a = (Read-Host -Pr
我在远程连接到 MySQL 服务器时遇到问题。我知道我的用户设置了来自任何主机的“%”通配符,因此我应该有权访问服务器。我可以使用我的凭据本地登录 MySQL 服务器,但不能远程登录。 我在 my.c
我正在尝试使用 angular 2 构建一个双主题应用程序。有问题的组件 css 已经使用 :host/deep/强制对子组件进行样式设置。 但是我正在尝试根据 html 主题切换此样式,并且我正在使
我需要将特定的传出连接(从我系统上的任何 网络客户端)重定向到特定的 IP。是的,可以通过在 /etc/hosts 文件中添加这一行来完成: 123.456.789.012 www.mydomain
尝试在开发中预览我的邮件程序,但出现上述错误。(使用 Michael Hartl 教程)。 我相信它因为我的主机而无法正常工作。但是,使用 cloud 9 我很难找到我的主机。在书中,它被定义为 Cl
nc 当我在虚拟机上执行它时工作正常。 Connection to 10.0.0.10 22 port [tcp/ssh] succeeded! 但是当我在 docker 容器内执行相同的命令时,它会
我正在学习PowerShell,想知道两者之间的区别 Read-Host -Prompt "Text" 和 Read-Host "Text" 是同一件事还是我没有看到的区别? 最佳答案 这是同一件事。
我无法对 Cassandra 节点进行查询。我能够连接到集群并进行连接。然而,在执行查询时,它失败了 Caused by: com.datastax.driver.core.exceptions.No
我有这样的场景,比如我需要运行一个位于 12.34.567 的 API curl 请求,登录后我必须再登录一台主机 98.76.543。 登录到第二个主机后,我必须运行curl -XPOST -H"C
当我尝试 git push -u origin master到我的存储库,我得到 400 Bad Request .我特意用 编辑了一些信息。 最近从 gitlab-ee 中解绑了 nginx,并验
假设我有某个程序的源代码,源代码使用 GNU autotools,为了简单起见,假设该程序绝不是任何类型的开发工具。如果我手边有交叉工具链,我可以使用 --host configure 为平台 foo
在我的 ASP.NET Core 2.0 项目中,我一直在使用 Microsoft.Extensions.Hosting 命名空间中的 IHostingEnvironment 和 IApplicati
我正在使用以 Python3.6 为基础的 docker 镜像。突然间它开始崩溃(启动后立即退出)。所以我冲进了容器,发现它崩溃是因为与容器化 postgres 数据库的连接突然失败。我设法得到的唯一
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我尝试使用 ssh命令连接到另一个远程主机。 ssh -p 21098 -i $OPENSHIFT_DATA_DIR/.ssh/host_key user@domain.com The authe
我是一名优秀的程序员,十分优秀!