5 Replies - 573 Views - Last Post: 24 February 2017 - 02:05 PM

#1 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 240
  • Joined: 29-October 16

Using For Loops to Generate String References

Posted 24 February 2017 - 12:14 PM

So lets say that I've already declared managed String^ (s) 1-6 as result1-6

String^ result0
String^ result1
String^ result2
String^ result3
String^ result4
String^ result5
String^ result6



and now I want to reference each one of them with the following command using a loop:
	for (int zz ; zz <= 6 ;zz++ )
	{
		result(zz)
		result(zz) = textBox1->Text;
		stdstring = marshal_as<std::string>(result(zz));
		ofstream myfile(zz);
		myfile(zz).open("Info(zz).txt");
		myfile(zz) << stdstring(zz);
		myfile(zz).close();
	}




Now I know that's not how I do it but can anyone tell me how that should work? Do I have to create an object class to do it? If not what's your suggestions... and pragmatism is king for me.. the simpler the better.

Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: Using For Loops to Generate String References

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13346
  • View blog
  • Posts: 53,141
  • Joined: 12-June 08

Re: Using For Loops to Generate String References

Posted 24 February 2017 - 12:32 PM

What is the case for this?
Why not an array?
Was This Post Helpful? 0
  • +
  • -

#3 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 240
  • Joined: 29-October 16

Re: Using For Loops to Generate String References

Posted 24 February 2017 - 12:54 PM

ah ok... so should I use an array instead of a loop?

oh and what do you mean by case? As in what am I using it for?
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5783
  • View blog
  • Posts: 19,682
  • Joined: 05-May 12

Re: Using For Loops to Generate String References

Posted 24 February 2017 - 01:21 PM

Moving to C++/CLI...
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13346
  • View blog
  • Posts: 53,141
  • Joined: 12-June 08

Re: Using For Loops to Generate String References

Posted 24 February 2017 - 01:25 PM

Yeah - what is the business/use case for why would you specifically want to try and have individual variables dynamically named versus an array or collection.
Was This Post Helpful? 0
  • +
  • -

#6 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 240
  • Joined: 29-October 16

Re: Using For Loops to Generate String References

Posted 24 February 2017 - 02:05 PM

Well I'm using it for a program that will save the contents of a textbox to 6 different strings. I really don't care how it happens, I was going to use a loop to save 6 different string to six different files without having to re-write the code for each instance of the save to string.

If you say I should use an array I will take your word for it, and go from there; you're way more experienced than me, and know better than I.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1