我想在文件中找到一个字符串,并用用户输入替换它.
这是我的粗略代码.
#include <iostream>
#include <fstream.h>
#include <string.h>
int main(){
istream readFile("test.txt");
string readout,
search,
replace;
while(getline(readFile,readout)){
if(readout == search){
// How do I replace `readout` with `replace`?
}
}
}
Run Code Online (Sandbox Code Playgroud)
更新
这是解决我的问题的代码
的test.txt:
id_1
arfan
haider
id_2
saleem
haider
id_3
someone
otherone
Run Code Online (Sandbox Code Playgroud)
C++代码:
#include <iostream>
#include <fstream>
#include <string>
using namesapce std;
int main(){
istream readFile("test.txt");
string readout,
search,
firstname,
lastname;
cout << "Enter the id which you want to modify";
cin >> search;
while(getline(readFile,readout)){
if(readout == search){
/* …Run Code Online (Sandbox Code Playgroud) 我不确定在PHP 中使用__get和__set方法有什么价值.
这是在数组中设置值的代码.
class myclass {
public $sotre = array();
public function __set($arraykey,$value){
echo 'Setting '.$arraykey.' to '.$value;
$this->store[$arraykey] = $value;
}
}
$obj = new myclass;
$obj->a = 'arfan';
Run Code Online (Sandbox Code Playgroud)
这是另一个代码.
class myclass {
public $sotre = array();
public function setvalue($arraykey,$value){
echo 'Setting '.$arraykey.' to '.$value;
$this->store[$arraykey] = $value;
}
}
$obj = new myclass;
$obj->setvalue('a','arfan');
Run Code Online (Sandbox Code Playgroud)
这两个函数都做同样的事情.
代码使用__get/ __setmagic方法:
class myclass {
public $store =
array(
'a'=>'arfan',
'b'=>'azeem',
'c'=>'hader'
);
public function __get($arraykey){ …Run Code Online (Sandbox Code Playgroud) 我做了一个代码,应该突出搜索字符串,但它不起作用.
这是代码:
<body>
<div>div is here</div>
<div id="divid">
<div>this is a div 1</div>
<div> this is a div 2</div>
<div> this is a div3</div>
</div>
<div> another div is here</div>
</body>
Run Code Online (Sandbox Code Playgroud)
这是一个javascript代码.
function checkit(){
var hlWord = "div";
var nregex = new RegExp(hlWord,"gi");
var div = document.getElementById("divid").getElementsByTagName('div');
for(var i=0; i <= div.length; i++){
var div1 = div[i].innerHTML;
var rword = div1.replace(nregex,"<b>"+hlWord+"</b>");
div1.innerHTML = rword;
}
}
Run Code Online (Sandbox Code Playgroud) 我不明白为什么__unset()不工作.
class myclass {
public $name = array();
public function __set($arraykey, $value){
$this->name[$arraykey] = $value;
}
public function __isset($argu){
return isset($this->name[$argu]);
}
public function __unset($argu){
echo "Working: Unset $this->name[$argu]";
unset($this->name[$argu]);
}
}
$obj = new myclass;
$obj->name = 'Arfan Haider';
var_dump(isset($obj->name));
unset($obj->name);
Run Code Online (Sandbox Code Playgroud)
我读到只要unset()调用该函数,就会__unset()自动调用Magic Method 并取消设置变量.
在上面的代码我使用unset但它没有调用__unset().为什么?我在理解魔术方法时遗漏了什么__unset()?
我想在不重新加载页面的情况下更改浏览器栏中的URL.
<html><head>
<title>Change url in browser bar</title>
</head>
<body>
<h1>Refresh page to see our other website</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当任何用户进入我的网站,如www.a-site.com打开此网站后,他会看到文本 刷新页面,以查看我们的其他网站.我能做到这一点,当他在进入www.a-site.com,就像在浏览器栏这个网址变更后www.b-site.com当用户刷新页面可以automaticaaly重定向
www.b-site.com.这是可能的吗?
谢谢...............
我想从Mysql表中删除所有重复的行.
但问题是我不知道哪些行是重复的.
这个Mysql表包含一个大约500000行的大数据.
其中一些行是重复的.
请指导我如何做到这一点.
更新:
我需要在phpMyAdmin中运行的SQL查询.
这是一个粗略的表格来理解.
假设表名是foo.
+---------------------------------------------------------------------+
| id | link | title | description |
+---------------------------------------------------------------------+
| 1 | google | search engine | search here free |
| 2 | yahoo | also search engine | findout web easily |
| 3 | Facebook| connect with world | meet with world |
| 4 | google | search engine | search here free |
| 5 | msn | Microsoft network | network …Run Code Online (Sandbox Code Playgroud)