Hey all, this is my first post, but this site contributed to me learning c++ 4 years ago, and now that im getting into it again... having advanced in programming using other languages, im running into little qwerks I'd not known in c++.
Yes feel free to blame scripting languages, but I still need to solve the issue.
Working on a poject, anyway the example code takes a file whihc contains 30 lines of ip's.
I'm throwing that file into an array, and trying to pass it back up to main to print it. By doing that i'll be free to use similiar mechanics to send it to another function instead.
I've been reading up on returning array in c++, and while I've tried many functions and methods nothing seems to be working. When I DO get a peice of code that compiles, I get the dismal messagebox "this program has stop working, windows is search for a solution".
Here is my most recently adapted code using this example:
http://www.velocityreviews.com/forums/showpost.php?p=1482925&postcount=2
Any help would be greatly appreciated. I've been stuck in higher level langauges the last couple of years, it actually took me 3 days to get working sockets under windows with c++.... was damn close to just using perl -.-
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 26 27 28 29 30
|
string* get_peers_from_file()
{
string line;
string *array = new string[29];
int count=0;
ifstream peer_list("peer_list");
if(peer_list.is_open())
{
while (!peer_list.eof()){
getline(peer_list,line);
array[count]=line;
count++;
}
peer_list.close();
}
else cout << "Fatal Error: Cannot open peers list" << endl;
return array;
}
int main()
{
string *peer_list=0;
peer_list=get_peers_from_file();
for (int i=0; i<29; i++) {
cout << peer_list[i];
}
delete [] peer_list;
return 0;
}
|