我正在尝试运算符重载,我的头文件包括:
#ifndef PHONENUMBER_H
#define PHONENUMBER_H
#include<iostream>
#include<string>
using namespace std;
class Phonenumber
{
friend ostream &operator << ( ostream&, const Phonenumber & );
friend istream &operator >> ( istream&, Phonenumber & );
private:
string areaCode;
string exchange;
string line;
};
#endif // PHONENUMBER_H
Run Code Online (Sandbox Code Playgroud)
和类的定义
//overload stream insertion and extraction operators
//for class Phonenumber
#include <iomanip>
#include "Phonenumber.h"
using namespace std;
//overloades stram insertion operator cannot be a member function
// if we would like to invoke it with
//cout<<somePhonenumber
ostream …Run Code Online (Sandbox Code Playgroud) 我有档案:
<country=HK>
TCN=1
CURR_TYPE="RS"
PRICE=10
COMP_NAME="IBM"
TCN=2
CURR_TYPE="RS"
PRICE=200
COMP_NAME="CTS"
TCN=3
CURR_TYPE="RS"
PRICE=50
COMP_NAME="TCS"
endHK
<country=JN>
TCN=1
CURR_TYPE="YEN"
PRICE=10
COMP_NAME="IBM"
TCN=2
CURR_TYPE="YEN"
PRICE=200
COMP_NAME="CTS"
TCN=3
CURR_TYPE="YEN"
PRICE=50
COMP_NAME="TCS"
</country=JN>
Run Code Online (Sandbox Code Playgroud)
现在我想使用Perl脚本从上面文件中的成员中检索值.
我的Perl脚本文件是:
#!perl
open(FH, "<a.txt");
@a=<FH>;
$b=$#a;
for ($n=0;$n<$b;$n++)
{
if ($a[$n]=~/HK/)
{
foreach $_ ( @a[$n..($n+300)])
{
if($_ =~ /endHK/){ exit 0;}
print $_;
}
}
}
close(FH);
Run Code Online (Sandbox Code Playgroud)
请附加代码以帮助我从上面的文件中检索数据.