简单的文件读写 c++

#include
#include
#include
#include
#include

using namespace std;

struct bbox {
	double x, y, w, h;
};

void  read_detectResult(const string& file,vector&  detect_result,unsigned int frame_id)
{
	ifstream infile(file);
	if (!infile.is_open())
	{
		std::cout << "can not find detect result" << std::endl;
		return;
	}

	string line;

	while (getline(infile, line))
	{
		vector bboxs;
		std::stringstream ss(line);
		unsigned int x;
		ss >> x;
		if (x != frame_id)
			continue;
		//std::cout << "Frame ID :" << x << std::endl;
		bbox  box;
		int i = 0;
		while (ss >> x)
		 {
			switch (i % 4)
			{
			case 0:
			{
				box.x = x;
				std::cout << x << " ";
				break;
			}
			case 1:
			{
				box.y = x;
				std::cout << x << " ";
				break;
			}
			case 2:
			{
				box.w = x;
				std::cout << x << " ";
				break;
			}
			case 3:
			{
				box.h = x;
				std::cout << x << std::endl;
				bboxs.push_back(box);
				break;
			}
			}
			++i;
		}
		break;
	}
	infile.close();
	return;
}

void write_detectResult(const string& file, const vector&  detect_result)
{
	ofstream outfile(file);
	
	return;
}

int main()
{
	vector detect_result;
	read_detectResult("detect_result.txt", detect_result,10);

	//ofstream outfile("test.txt", ios_base::app);
	////outfile.open("test.txt", ios_base::app);
	//outfile << 1 << " " << 2 << " " << 3 << " " << 5 << " " << 7 << " ";
	//outfile << 2 << " " << 2 << " " << 3 << " " << 5 << " " << 7 << " ";

	system("pause");
	return 0;
} 

 

你可能感兴趣的:(c++)