hi please help, c++ windows form code text box

Hesham AbdMalek Ramadan 1 Reputation point
2021-12-14T15:25:25.97+00:00

hi i have a code like this

cout << "pixels intensities = \n" << image1 << endl;
cout << "image rows=" << image1.rows << endl;
cout << "image cols=" << image1.cols << endl;
cout << "image pixel total=" << image1.total() << endl;
cout << "image channels=" << image1.channels() << endl;
cout << "image pixel depth=" << image1.depth() << endl;
//return a number from 0 to 6
int pixel_v = image1.at<uchar>(0, 0);
int max = 0, min = 255, sum = 0;
for (int i = 0; i < image1.rows; i++)
{
for (int j = 0; j < image1.cols; j++)
{
sum = sum + image1.at<uchar>(i, j);
if (image1.at<uchar>(i, j) > max)
{
max = image1.at<uchar>(i, j);
}
if (image1.at<uchar>(i, j) < min)
{
min = image1.at<uchar>(i, j);
}
}
}
float avg = sum / image1.total();
cout << "max_value=" << max << endl;
cout << "min_value=" << min << endl;
cout << "avg=" << avg << endl;

need to show the output it in a text box

Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 125.7K Reputation points
    2021-12-14T16:18:35.607+00:00

    Check this technique:

    #include <sstream>
    
    . . .
    
    using namespace std;
    stringstream cout;
    const char* endl = "\r\n";
    
    // Your current code that uses 'cout':
    
    cout << "pixels intensities =" << image1 << endl;
    cout << "image rows=" << image1.rows << endl;
    . . . etc.
    
    textBox1->Text = gcnew String( cout.str( ).c_str( ) );
    
    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.