- #1
sketos
- 56
- 0
Hello,
I am relevant new user to C++ while i am quit comfortable using fortran!
One of my favourite thing to use in fortran was the subroutines but i struggling to find something similar in C++. Let me give you an example:
In Fortan:
while in c++ it's a bit tricky to do the same easy task. What i tried to do is to use pointers (for example i input an array in func and get another array as a return after i have done some calculations using the input array).
...
...
Is there another way to do this more straitforward or i have to get used to pointers?
I am relevant new user to C++ while i am quit comfortable using fortran!
One of my favourite thing to use in fortran was the subroutines but i struggling to find something similar in C++. Let me give you an example:
In Fortan:
subroutine test(Tabular1,Tabular2)
...
...
Tabular2(i)=expresion<Talular1(i)>
...
...
end
...
...
Tabular2(i)=expresion<Talular1(i)>
...
...
end
while in c++ it's a bit tricky to do the same easy task. What i tried to do is to use pointers (for example i input an array in func and get another array as a return after i have done some calculations using the input array).
...
...
int func(int *pt1,int *pt2)
{
for(int i=0 ; i<5 ; i++)
{
*(pt2+i)=*(pt1+i)+1;
}
return *pt2;
}
int main()
{
int vec[5]={1,1,1,1,1};
int vac[5]; func(&vec[0],&vac[0]);
for(int i=0 ; i<5 ; i++)
{
cout<<vac<<endl;
} return 0;
}
{
for(int i=0 ; i<5 ; i++)
{
*(pt2+i)=*(pt1+i)+1;
}
return *pt2;
}
int main()
{
int vec[5]={1,1,1,1,1};
int vac[5]; func(&vec[0],&vac[0]);
for(int i=0 ; i<5 ; i++)
{
cout<<vac<<endl;
} return 0;
}
Is there another way to do this more straitforward or i have to get used to pointers?