我得到了关注而无法弄明白。任何一点。
#include<iostream>
#include<string>
#include<vector>
using namespace std;
typedef std::vector<std::string> fom_header;
typedef std::vector<fom_header> fom_data;
void print_data(fom_data &f)
{
vector<fom_header>::iterator _header;
vector<string>::iterator _data;
for(_header = f.begin(); _header != f.end(); _header++)
{
for(_data = _header->begin(); _data != _header->end(); _data++)
{
cout<<"data ..."<<*_data;
}
}
}
int main()
{
fom_header.push_back("A");
fom_header.push_back("10");
fom_header.push_back("20");
fom_header.push_back("30");
fom_data.push_back(fom_header);
fom_header.push_back("B");
fom_header.push_back("30");
fom_header.push_back("40");
fom_header.push_back("50");
fom_data.push_back(fom_header);
print_data(fom_data);
}
错误
create_2d.cpp:24:15: error: expected unqualified-id before ‘.’ token
create_2d.cpp:25:15: error: expected unqualified-id before ‘.’ token
create_2d.cpp:26:15: error: expected unqualified-id before ‘.’ token
create_2d.cpp:27:15: error: expected unqualified-id before ‘.’ token
create_2d.cpp:28:13: error: expected unqualified-id before ‘.’ token
create_2d.cpp:30:15: error: expected unqualified-id before ‘.’ token
create_2d.cpp:31:15: error: expected unqualified-id before ‘.’ token
create_2d.cpp:32:15: error: expected unqualified-id before ‘.’ token
create_2d.cpp:33:15: error: expected unqualified-id before ‘.’ token
create_2d.cpp:34:13: error: expected unqualified-id before ‘.’ token
create_2d.cpp:36:24: error: expected primary-expression before ‘)’ token
答案 0 :(得分:2)
fom_header
是一种类型。您需要该类型的实例:
fom_header hdr;
hdr.push_back("hello");
同样适用于fom_data
。
答案 1 :(得分:1)
fom_header
这里只是一个类型,而不是vector<string>
变量。您需要在调用push_back()
之前定义此类型的变量(并且您需要对fom_data
执行类似的操作):
fom_header fom;
fom.push_back("A");