我一直在研究 Microsoft Visual C++ 2010(32 位系统)
在编译阶段,我收到一条错误消息:
1>------ Build started: Project: pruebavecot, Configuration: Debug Win32 ------
1> pruebavecot.cpp
1>c:\users\andresgraco\desktop\pruebavecot\pruebavecot\pruebavecot.cpp(64): error C2057: expected constant expression
1>c:\users\andresgraco\desktop\pruebavecot\pruebavecot\pruebavecot.cpp(64): error C2466: cannot allocate an array of constant size 0
1>c:\users\andresgraco\desktop\pruebavecot\pruebavecot\pruebavecot.cpp(64): error C2440: 'initializing' : cannot convert from 'std::string' to 'double *[]'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
代码:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("Vetor_Oscilacao.txt");
if (myfile.is_open())
{
int i=1;
while ( getline (myfile,line) )
{
cout << stod(line) << '\n';
for(double i=1; i<100; i++)
{
double in[i]=line;
}
}
myfile.close();
}
else cout << "Unable to open file";
getchar();
return 0;
}
我正在尝试从 .txt 文件接收数据并将其存储在向量中(在 [i] 中)以供以后在 fftw 中使用。.txt 文件中的数据组织如下:
21.000000
24.000000
25.000000
25.000000
21.000000
22.000000
24.000000
25.000000
...(data #100)
非常感谢您的帮助。