C + + A project has two CPP files, in a CPP file to invoke another CPP file calculation results, how to achieve AH?

Source: Internet
Author: User

Put 1.cpp and 2.cpp in the same directory, for example:
The 1.cpp code is as follows
#include <iostream>

int main ()
{
void Changefunction (int* input, int n);
void Printdata (int* input, int n);

int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Printdata (A, 10);

Changefunction (A, 10);
Printdata (A, 10);

return 0;
}
The 2.cpp code is as follows
#include <iostream>

void Changefunction (int* input, int n)
{
for (int i = 0; i < n; i++)
{
Input[i] + = 10;
}
}

void Printdata (int* input, int n)
{
Std::cout << "=============================" << Std::endl;
for (int i = 0; i < n; i++)
{
Std::cout << Input[i] << "";
}
Std::cout << Std::endl;
Std::cout << "-----------------------------" << Std::endl;
}
Output Result:
=============================
1 2 3 4 5 6 7 8 9 10
----------------------------------------------
=============================
11 12 13 14 15 16 17 18 19 20
----------------------------------------------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C + + inside is a header file, the standard practice is: The header file inside the function declaration, the CPP function is implemented specifically. According to your description should be able to use a. h header file to put all the functions of the Declaration, and then put a function in 1.cpp, 2.cpp put another function, we put 1.cpp as the entry of the program as a data source, where the function called 2.cpp, this function returns the result of the calculation. Note that all two CPP includ header files

C + + A project has two CPP files, want to invoke another CPP file in a CPP file calculation results, how to achieve AH?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.