Hi,
this is a c++ doodle - beginning to learn how to read and write from a text file in c++. i think that will be helpful in learning c++ and using Blender to visualize the results.
#include <iostream>
//for writing to file
#include <fstream>
#include <iostream>
//for reading file
#include <sstream>
int main()
{
std::cout<<"topics hurraay"<<std::endl;
/*
//writing to a text file
std::string vstr = "great wrote some text info\n";
std::ofstream ofile("verts.txt");
ofile << vstr;
ofile.close();
//https://stackoverflow.com/questions/15388041/how-to-write-stdstring-to-file
*/
//reading from a text file
//ex 1
/*
std::string ivstr;
std::ifstream ifile("verts.txt");
std::getline(ifile, ivstr);
std::cout<<ivstr<<std::endl;
*/
//ex 2
std::string ivstr;
std::ifstream ifile("verts_dat.txt");
/*format of text file:
//x,y,z
10 20 30
5 10 15
25 32 10
*/
//skip first line
std::getline(ifile, ivstr);
double x,y,z;
//go through each line of text file
while(std::getline(ifile, ivstr))
{
std::istringstream iss(ivstr);
//save into variables
iss >> x >> y >> z;
std::cout<<"x,y,z:"<<x<<" "<<y<<" "<<z<<std::endl;
}
/*result
x,y,z:10 20 30
x,y,z:5 10 15
x,y,z:25 32 100
*/
//https://stackoverflow.com/questions/51007121/read-a-text-file-c
return 0;
}
//g++ -o prog topicsA.cpp
//./prog
and these are some exercises i made to help with learning c++.
//todo: class that reads and writes x,y,z points - reading just prints out what was read //todo: vector of structs - each struct a vertex (output vertex points from a cube in blender in python - input vertices in c++) //todo: class that reads and writes x,y,z points - reading saves points in structs //todo: translate x all vertices in c++ - output to text file in c++ - read the new point position in blender python //todo: class reads/writes animation keyframes - for simplicity //f,v - a frame and a value //todo: smooth keyframes - example for every frame its value is its before/cur/after values averaged
Happy Sketching!