-1
我试图从管道分隔文件中获取第2和第5列的详细信息。从管道分隔文件中获取值
第5列在从虚拟文件中读取时正在修剪。我也尝试使用get line功能。如何获得字符串中的整个第5列?
文件看起来像:
1|6705|SW|447|C/A-"WAR" FROM CAR COMPANY |||RFD|E|0|
2|6706|CA|448|CAR TYPE OR CUST. ID, REQ |||RFD|E|0|
3|6707|CZ|448|CAR TYPE OR CUST. ID, REQ |||RFD|E|0|
代码
std::string cmd = "awk -F'|' '{ print $2, $5 }' 1.txt >> tmp.txt";
system(cmd.c_str());// extract the two columns and write to dummy file
ifstream read("tmp.txt");
std::string line;
while (std::getline(read, line)) // Read the file line by line
{
std::istringstream iss(line);
string a, b;
if (!(iss >> a >> b)) { break; } // error
std::cout<<"a"<<a<<" b "<<b<<std::endl;
}
read.close();
system("rm tmp.txt");
输出
键(字符串):6705,值(INT):C/A-“WAR “
key(string):6706,value(int):CAR
key(string):6707,value(int) :CAR