use C++ WRITE svg
时间: 2024-03-12 14:48:15 浏览: 19
To write SVG using C++, you can use a library like CairoSVG. Here is some sample code that uses CairoSVG to create an SVG file with a red circle:
```c++
#include <cairo-svg.h>
int main() {
// Create a new SVG surface
cairo_surface_t *surface = cairo_svg_surface_create("output.svg", 400, 400);
cairo_t *cr = cairo_create(surface);
// Draw a red circle
cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
cairo_arc(cr, 200, 200, 100, 0, 2 * M_PI);
cairo_fill(cr);
// Clean up
cairo_destroy(cr);
cairo_surface_destroy(surface);
return 0;
}
```
This code creates an SVG file called "output.svg" with a 400x400 canvas and a red circle centered at (200, 200) with a radius of 100. You can modify the code to draw other shapes or add text to the SVG file.