2017-04-10 109 views
0

我已经创建了一个web界面,允许用户选择一个txt文件。我的C++程序会根据用户选择的txt文件进入文件夹并执行(基本上文本文件的内容是关于配置的,所以程序需要根据用户在网页上选择加载配置)。现在的问题是,如何将文本文件名传递给cpp程序。我用粗体和斜体标注的编码是行不通的,只是我想要实现的目的。C++从PHP获取变量?

int main(***string filename***) 
{ 
using namespace std; 
vector<string> strings; 

string path = "/home/pi/Desktop/DMixer_Webinterface_Downloadfile/"; 
string fullpath = path + ***filename***; 

// ifstream file("/home/pi/Desktop/DMixer_Webinterface_Downloadfile/abc_2017_03_10_23_24_52.txt"); 
ifstream file(fullpath); 
std::string str; 

while (std::getline(file, str, ',')) 
{ 
    myArray[array_count] = str; // store those value in array 
           // cout << str << "\n"; 
    strings.push_back(str); 
    array_count++; 
} 
x_gap_value = atof(myArray[2].c_str()); 
y_gap_value = atof(myArray[3].c_str()); 
return 0; 
} 
+0

所以你要学会如何处理C++程序的命令行参数?有成千上万的关于这个问题的例子和教程,以及它在很多书中都有描述。 –

+0

它是我从外部(从PHP)传递参数到C++的命令行然后它会工作吗? –

回答