我目前的代码:
$file = fopen("countries.txt","r");
$array = array();
while(!feof($file)) {
$array[] = fgets($file);
}
fclose($file);
Run Code Online (Sandbox Code Playgroud)
这是我的foreach循环:
$str = "test";
foreach ($array as $key => $val) {
if ($val == $str) {
echo $val;
} else {
echo "not found";
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道为什么它只是打印$ val,如果它是数组的最后一个值.
例如,如果txt文件看起来像这样,它就有效
test1
test2
test3
test
Run Code Online (Sandbox Code Playgroud)
但如果它看起来像这样不起作用
test1
test2
test
test3
Run Code Online (Sandbox Code Playgroud) 我写了这个小函数,按名称搜索进程并将其杀死:请参阅下面的代码
Process[] procList = Process.GetProcesses();
RegistryKey expKey = Registry.LocalMachine;
expKey = expKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
expKey.SetValue("AutoRestartShell", 0);
using (StreamWriter writer = new StreamWriter(@"C:\test\progtemp\Procs1.Txt", true))
{
int i = 0;
foreach (Process procs in procList)
{
writer.WriteLine(string.Format("Process Name {0} -- Process ID {1} -- Session ID {2}", procs.ProcessName, procs.Id, procs.SessionId));
if (procs.ProcessName == "explorer")
{
procList[i].Kill();
}
i++;
}
}
expKey.SetValue("AutoRestartShell", 1);
Run Code Online (Sandbox Code Playgroud)
我很好奇为什么当我告诉它杀死资源管理器时它会自动重启.我怎样才能使它不重新启动而你必须进入任务管理器并手动重新启动它?
我有这个程序,不会为我编译,我不明白为什么,我得到错误"numeric_limits"没有声明在这个范围和预期的主要表达式之前"int"
这是我的代码:
#include <iostream>
#include<string>
#include<vector>
using namespace std;
using std::endl;
using std::vector;
using std::cout;
int main(){
string lName;
int yourAge;
cout << "Please enter your last name: ";
cin >> lName;
cout << " Please enter your age: ";
cin >> yourAge;
cin.ignore(numeric_limits<int>::max(), '\n');
if (!cin || cin.gcount() != 1){
cout << "Invalid age, numbers only please \n";
return yourAge;
}
vector<string> lastNames;
lastNames.push_back("Jones");
lastNames.push_back("Smith");
lastNames.push_back("Whitney");
lastNames.push_back("Wang");
lastNames.push_back(lName);
for(int i = 0; i < lastNames.size(); i++) {
cout << …Run Code Online (Sandbox Code Playgroud)