首页 > 解决方案 > 如何将我的 C++ 代码与 Visual Studio C++ 中的表单连接起来?

问题描述

我对这件事真的很陌生,而且我正在迈出第一步,所以这可能是一个愚蠢的问题。我制作了一个在“Dev C++”程序中运行的 .cpp 文件。我需要可视化我的程序的一些结果(图表等),所以我需要以某种方式将我的代码与我在 Visual Studio 中制作的表单连接起来。结果每次都会改变,所以我不能只是手写。我的想法是有一个按钮,当用户单击它时,它将运行我的 c++ 程序,当结果准备好时,它们将在图表上执行。

我的代码现在是这样并且正在运行,但我还没有完成它,因为我现在的主要问题是找到一种从 Visual Studio 运行这个程序的方法,并以某种方式将它与一个按钮连接起来。

我应该调用 eventHandler 还是某事?我应该在我的 .cpp 文件上写一些东西,以便它可以以某种方式与表单连接吗?

使用命名空间标准;

/* 从字符串中提取所有整数 */ void extractIntegerWords(string str) { stringstream ss;

/* Storing the whole string into string stream */
ss << str; 

/* Running loop till the end of the stream */
string temp; 
int found; 
while (!ss.eof()) { 

    /* extracting word by word from stream */
    ss >> temp; 

    /* Checking the given word is integer or not */
    if (stringstream(temp) >> found) 
        cout << found << " "; 

    /* To save from space at the end of string */
    temp = ""; 
} 

}

//------------------------------------------------ -------------------------------------------

int main(int argc, char** argv) { int i=0,count_elements=0,a=0;

string line;
string keyword[2];


ifstream readyfile("file.map");
ofstream newfile("search_list.txt");



//Give the keywords
keyword[0] = {"Module                                            ro code "};
keyword[1] = {"Grand Total:"};


cout<< endl;



while(getline(readyfile,line))
{
    for(i=0;i<2;i++)
    {
        if (line.find(keyword[i]) != std::string::npos)
        {
            count_elements++;


            int n = line.length(); 
            line.erase(std::remove(line.begin(), line.end(), '\''), line.end());
            extractIntegerWords(line);
            newfile<<line<<endl;
        }           
    }
}   

cout<<"Process has been completed!"<<endl;
cout<<"There have been "<<count_elements<<" elements found and written on the file"<<endl;

readyfile.close();
newfile.close();


system("pause");
return 0;

}

标签: c++formsbuttonvisual-c++visual-studio-2019

解决方案


推荐阅读