Push array

Jul 23, 2019 at 6:37am
How to push array c++?

This is my code, i want get value(array) to use another function ..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <conio.h>
#include <string>

using namespace std;
int main()
{
string Huruf[] = {"A", "B", "C", "D", "E"};
int arr[10] = { 10, 25, 30, 40, 30, 25, 40, 10, 15, 15 };
int no[] = {1, 2, 3, 4, 5, 0};

for (int n = 0; no[n];n++){
	cout<<"Titik "<<no[n]<<" = "<<Huruf[n]<<endl;
}

//A-B = 10, A-C = 25, A-D = 30, A-E = 40, B-C = 30, B-D = 25, B-E = 40, C-D = 10, D-E = 15, C-E = 15.
cout<<"Sisi-sisinya = ";
for (int i=0; i<5; i++){
	for (int j=i+1; j<5; j++){
	cout<<Huruf[i]+Huruf[j]<<" ";
	}
}


}

This is result if run:
Sisi-sisinya = AB AC AD AE BC BD BE CD CE DE

I want to get value "AB AC AD AE BC BD BE CD CE DE" and then to push for use another function
Last edited on Jul 23, 2019 at 6:54am
Jul 23, 2019 at 6:51am
Please edit your post to put [code][/code] tags around your code. Use the <> format.
http://www.cplusplus.com/articles/jEywvCM9/
Jul 23, 2019 at 7:01am
okay, i have done change format to put ..
Jul 23, 2019 at 7:02am
I'm not sure to fully understand what you want, but...

If you want to store the entire result, just use a string :
myResult+=Huruf[i]+Huruf[j];

If you want to store each result (AB and AC and AD etc...)
Use a vector like this :
1
2
3
4
5
6
7
8
#include <vector>
...
std::vector<std::string> v;
for (int i=0; i<5; i++){
	for (int j=i+1; j<5; j++){
	        v.push_back(Huruf[i]+Huruf[j]);
	}
}


And so, v[0]=AB, v[1]=AC, etc...
Jul 23, 2019 at 7:13am
Yeah, I mean like that @Zaap
. Thanks u!
Topic archived. No new replies allowed.