Re: [Dev-C++] how to pass a string array to another function
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Brad <nyc...@gm...> - 2012-09-17 12:40:48
|
That's the problem, my function is not in main() and this is where the
errors get weird is when I pass the same arguments in a function outside of
main.
Brad
From: bibigiu [mailto:bi...@al...]
Sent: Monday, September 17, 2012 8:04 AM
To: Brad
Subject: Re: [Dev-C++] how to pass a string array to another function
Il 17/09/2012 13:40, Brad ha scritto:
My situation is this, I have a string array that I am trying to get the data
to another function but have issues with the return type conflicting with
either the function definition or the array data being passed.
std::array Array[2]
std::string f()
{
array[0]=ted
array[1]=bundy
return Array[2];
}};
void printarray (int arg[], int length) {
for (int n=0; n<length; n++)
cout << Array[n] << endl;
}
int main ()
{
printarray();
return 0;
}
try this :
#include <iostream>
using namespace std;
void PrintArray(std::string str[],int length)
{
for(int a=0;a<length;a++)
{
cout<< str[a].c_str() << endl;
}
}
int main()
{
std::string str[2];
str[0] = "hello";
str[1] = "bye";
PrintArray(str,2);
return 0;
}
----------------------------------------------------------------------------
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|