c++中一个神奇的报错
// FileRead.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <atlstr.h>
#include<vector>
using namespace std;
//文本文件读文件
void fileRead(string fileName) {
//1、包含头文件
//2、创建流对象
ifstream ifs;
//3、打开文件并且判断是否打开成功
ifs.open(fileName + ".txt",ios::in);
// 4、读数据
char* buf;
//一行一行读入数据
vector<vector<string>> fields;
//string a; // 这里是一个神奇的地方,不加就会报错,然而它也没有被使用到
char buff[10];
while (ifs != NULL && ifs >> buff) {
vector<string> field;
// 先放入第一个
char* p = strtok(buff,",");
// 继续分割直到结果为NULL
while(p!=NULL){
field.push_back(p);
p = strtok(NULL,",");
}
fields.push_back(field);
}
//5、关闭文件
ifs.close();
}
int main(){
fileRead("属性");
system("pause");
return 0;
}
FldID,LayerID,字段名
0 ,0 ,河流名称
1 ,0 ,河流长度
2 ,1 ,绿地名称
3 ,1 ,绿地面积
4 ,2 ,草地权属
5 ,3 ,建筑名称
6 ,3 ,建筑面积
7 ,3 ,建筑结构
LayerID, 层名,最大显示比例,最小显示比例
0 , 河流,0.01 ,1.0
1 , 绿地,0.02 ,1.1
2 , 草地,0.03 ,1.2
3 , 建筑,0.04 ,1.3