Author Topic: ...Use vectors?  (Read 2774 times)

flyer

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
...Use vectors?
« on: April 27, 2012, 12:50:41 am »
Hi there,

I have a question regarding the use of vectors within DFSDK.

Is it correct that C# does not support vectors any more?  If so then during the conversion process, will this cause a problem or is your system able to cope with this?

And maybe on a more general C++ issue...

I am having to use std::vector<... when I create my vectors.  I understand that adding "using namespace std" could prevent the need for the std:: but I also read that this is maybe not the best idea when programming in C++.

Does anyone have any pearls of wisdom for me?  :)

Thanks all,


Steve

martol1ni

  • Guest
Re: ...Use vectors?
« Reply #1 on: April 27, 2012, 01:07:12 am »
In my projects, I am using vectors, compiling through the build center and over to the iphone works like a charm. Just remember to #include <vector> , and as you say, don't use namespace std. Use std::vector (or std::whateverelseyouareusing) :) The std is also only once.

Code: [Select]
std::vector<int> myVector;
for (int i=0; i<5; i++)
    myVector.push_back(i);

nednones

  • Guest
Re: ...Use vectors?
« Reply #2 on: April 28, 2012, 05:50:47 am »
on the same note, does anyone know how we can incorporate strings, and I mean proper strings not char *[]/char []?

budershank

  • Guest
Re: ...Use vectors?
« Reply #3 on: April 28, 2012, 07:18:33 am »
#include <string>

nednones

  • Guest
Re: ...Use vectors?
« Reply #4 on: April 29, 2012, 04:23:17 am »
I understand you can incoporate #include <string> but to use the syntax in the code???

budershank

  • Guest
Re: ...Use vectors?
« Reply #5 on: April 29, 2012, 04:33:51 am »
Well... not sure what you want to do with the string, but you can declare a variable like this


Code: [Select]
std::string myStr = "Chicks dig budershank";
or

Code: [Select]
std::string myStr("chicks dig budershank");

If you want to use that string in lets say a TextAdd or NoteAdd you would need to convert it back to a char using sprintf(myChar, myStr.c_str());




nednones

  • Guest
Re: ...Use vectors?
« Reply #6 on: April 29, 2012, 04:44:59 am »
That was going to lead me onto my next question. Is it safe to use the std::string and the associated methods on an IOS device?

martol1ni

  • Guest
Re: ...Use vectors?
« Reply #7 on: April 29, 2012, 04:50:00 am »
That was going to lead me onto my next question. Is it safe to use the std::string and the associated methods on an IOS device?

Yes that is perfectly fine. I've been using both strings and vectors in my app, and it never crashes. Just beware if index errors and so in vectors. Objective-c has strings too, called NSString. It should all work perfectly fine.

Edit: aoch..
« Last Edit: April 29, 2012, 08:13:39 am by martol1ni »

budershank

  • Guest
Re: ...Use vectors?
« Reply #8 on: April 29, 2012, 06:11:05 am »
Err, might want to fix the rather out of context typo in your reply, mart!

nednones

  • Guest
Re: ...Use vectors?
« Reply #9 on: April 30, 2012, 06:46:34 am »
Yer, I wanted to make use of strings since the cstring class provides many overload methods which are useful for comparison and grabbing strings from netsend responses