Write data to a. txt file
Writes data to a. txt file
vector<point2f> quad_pts;
Quad_pts.push_back (point2f ( -602.935, 464.887));
Quad_pts.push_back (point2f ( -401.548, 477.997));
Quad_pts.push_back (point2f ( -1346.625, 261.575));
Quad_pts.push_back (point2f ( -129.836, 283.220));
Ofstream F1 ("Points.txt");//#include <fstream>
char savepoints[100];//character array
strcpy_s (savepoints, " Quad_pts ");
F1 << savepoints << Endl;
for (int i = 0; i < quad_pts.size (); i++)
{
sprintf_s (savepoints, "px%fy%f", quad_pts[i].x, QUAD_PTS[I].Y); C12/>f1 << savepoints << Endl;
}
To read the. txt file data into C + +
Read data from. txt
ifstream myFile;
Myfile.open ("Points.txt");
Char output[100];
if (Myfile.is_open ())
{while
(!myfile.eof ())
{
myFile >> output;
cout << output << Endl;
}
Myfile.close ();
Gets the part string between the two tag strings
std::string cf_getmiddlestr (std::string srcstr, std::string startmarkstr, std::string EndMarkStr)
{
size_t Startpos, Endpos, length;
startpos = Srcstr.find (startmarkstr, 0);
Endpos = Srcstr.find (endmarkstr, 0);
Length = Endpos-startpos-startmarkstr.size ();
std::string resstr = srcstr.substr (startpos + startmarkstr.size (), length);//The second parameter represents the length return
resstr;
}
The part of the string that precedes the tag string
std::string cf_getstartstr (std::string srcstr, std::string endmarkstr)
{size_t endpos ;
Endpos = Srcstr.find (endmarkstr, 0);
std::string resstr = srcstr.substr (0, endpos);
return resstr;
}
The part of the string after the token string
std::string cf_getendstr (std::string srcstr, std::string startmarkstr)
{size_t startpos
, length;
startpos = Srcstr.find (startmarkstr, 0);
Length = Srcstr.size ()-startpos-startmarkstr.size ();
std::string resstr = srcstr.substr (startpos + startmarkstr.size (), length);
return resstr;
}