[英]How to read in complex data from file and input in to array in C++
我有一个包含 1000 个复数样本的 csv 文件,我想将它们读入 C++ 中的数组,准备好进行数据操作(这将复数乘以一个系数)。 我对 C++ 没有经验,所以我不确定如何了解 go。 一个简单,容易的解决方案将不胜感激。
我的 csv 片段如下所示。
25.0000000000000 + 0.00000000000000i, -9.04508497187474 + 18.3273439473386i, -3.45491502812526 - 8.38799522150257i, -3.45491502812527 + 8.38799522150257i, -9.04508497187474 - 18.3273439473386i, 25.0000000000000 - 9.79717439317883e-15i,...
任何帮助,将不胜感激。
首先,您可以使用以下命令读取逗号分隔值文件:
std::ifstream file;
// open file
std::string complex_str;
while (getline(file, complex_str, ',')) {
// process complex_str
// store real and imaginary parts in your array
}
您可能想使用正则表达式来解析complex_str
以提取您的实部和虚部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.