How is a string vector array declared using a Form application ?

This seems to work for int in a Form Application:

std::vector<int> Value(10);

But if you change int to string in the same example the compiler
says that 'std::vector' : class has no constructors

It isn't complaining about the std::vector class, but the string class, which doesn't exist.

Make sure you say: std::vector<std::string> Value(10); Hope this helps.

yes that worked great...thanks. The compiler said that string also not was declared so std:: was the trick.

I have:
Directory::GetFiles(Files,"*.txt");

Files is in a format: cli::array<Type,dimension> ^

How could Files be converted to System::string ^


It isn't complaining about the std::vector class, but the string class, which doesn't exist.

Make sure you say: std::vector<std::string> Value(10); Hope this helps.

Alas, I've never played with MFC.

I wonder if you wanted a vector of System::String? std::vector<[B]S[/B]tring> Value(10); (Case matters.)

Okay I see, std::string was fine.
I have a big problem with this conversion from cli::array<type,dimension> to System::string ^. See if anyone have any idea to that.

Alas, I've never played with MFC.

I wonder if you wanted a vector of System::String? std::vector<[B]S[/B]tring> Value(10); (Case matters.)

> I have: Directory::GetFiles(Files,"*.txt");
> Files is in a format: cli::array<Type,dimension> ^
> How could Files be converted to System::string ^

presumably, the Type in cli::array<Type,dimension> is wchar_t and the dimension is 1.
all cli array types derive from System::Array and you could directly use the constructor of a System::String that accepts a Char[] . http://msdn2.microsoft.com/en-us/library/ttyxaek9.aspx

alternatively, you could use the static array<String^>^ GetFiles( String^ path ) http://msdn2.microsoft.com/en-us/library/07wt70x2.aspx which will return an array of *all* files in the directory. you could then test each file name to see if it ends in ".txt" by using bool System::String::EndsWith( System::String^ ) http://msdn2.microsoft.com/en-us/library/2333wewz.aspx

Thanks for the answer. I have red these examples many times without really understand exactly what is needed. From what I am doing in my code I cant find what I am doing wrong:
From what I can understand I am saving Files to on array of System::string ^ but unfortunately I do not as the compiler still says that:

cannot convert parameter 1 from 'cli::array<Type> ^' to 'System::string ^'

I have struggling with this for a week and red every example on the net. What is missing in my code ?
Thanks in advance!

folderBrowserDialog1->ShowDialog();
System::String ^ Files = folderBrowserDialog1->SelectedPath; 

array<System::String ^> ^ files4 = System::IO::Directory::GetFiles(Files,"*.txt");

this->textBox1->Text = files4;

> I have: Directory::GetFiles(Files,"*.txt");
> Files is in a format: cli::array<Type,dimension> ^
> How could Files be converted to System::string ^

presumably, the Type in cli::array<Type,dimension> is wchar_t and the dimension is 1.
all cli array types derive from System::Array and you could directly use the constructor of a System::String that accepts a Char[] . http://msdn2.microsoft.com/en-us/library/ttyxaek9.aspx

alternatively, you could use the static array<String^>^ GetFiles( String^ path ) http://msdn2.microsoft.com/en-us/library/07wt70x2.aspx which will return an array of *all* files in the directory. you could then test each file name to see if it ends in ".txt" by using bool System::String::EndsWith( System::String^ ) http://msdn2.microsoft.com/en-us/library/2333wewz.aspx

> What is missing in my code ?
the Text property of the ListControl is a System::String.
(it represents the currently selected string of the list control).
the variable file4 is an array of System::String ie. cli::array< System::String ^ > ^
if you want to set the selected string into the first element of this array, you could write

if( file4.Length > 0 )
     this->textBox1->Text = files4[0] ;

Wow! That worked really great. Thank You very much.
Next step is to put all .txt files that is in that choosen folder in the textBox1 under eachother "\n"

I have tried this with a foor loop like this. I have 4 files in the folder I am opening. With this code I will put the second file in the folder to the textBox1.
I dont know if this code works but writes over every file catched with the for loop because "\n" is not happening in the textBox1
Am I thinking right here ?:
Thank you...

folderBrowserDialog1->ShowDialog();
System::String ^ Files = folderBrowserDialog1->SelectedPath; 

array<System::String ^> ^ files4 = System::IO::Directory::GetFiles(Files,"*.txt");
		
		

		for (int count = 0; count < 2; count++)
		
		{
		if( files4->Length > 0 )
		this->textBox1->Text = files4[count] ;
		}

Thanks for the answer. I have red these examples many times without really understand exactly what is needed. From what I am doing in my code I cant find what I am doing wrong:
From what I can understand I am saving Files to on array of System::string ^ but unfortunately I do not as the compiler still says that:

cannot convert parameter 1 from 'cli::array<Type> ^' to 'System::string ^'

I have struggling with this for a week and red every example on the net. What is missing in my code ?
Thanks in advance!

folderBrowserDialog1->ShowDialog();
System::String ^ Files = folderBrowserDialog1->SelectedPath; 

array<System::String ^> ^ files4 = System::IO::Directory::GetFiles(Files,"*.txt");

this->textBox1->Text = files4;

Wow! That worked really great. Thank You very much.
Next step is to put all .txt files that is in that choosen folder in the textBox1 under eachother "\n"

I have tried this with a foor loop like this. I have 4 files in the folder I am opening. With this code the second file in the folder is opened. I dont know if this code works but writes over every file catched with the for loop because "\n" is not happening in the textBox1
Am I thinking right here ?:
Thank you...

folderBrowserDialog1->ShowDialog();
System::String ^ Files = folderBrowserDialog1->SelectedPath; 

array<System::String ^> ^ files4 = System::IO::Directory::GetFiles(Files,"*.txt");
		
		

		for (int count = 0; count < 2; count++)
		
		{
		if( files4->Length > 0 )
		this->textBox1->Text = files4[count] ;
		}

Thanks for the answer. I have red these examples many times without really understand exactly what is needed. From what I am doing in my code I cant find what I am doing wrong:
From what I can understand I am saving Files to on array of System::string ^ but unfortunately I do not as the compiler still says that:

cannot convert parameter 1 from 'cli::array<Type> ^' to 'System::string ^'

I have struggling with this for a week and red every example on the net. What is missing in my code ?
Thanks in advance!

folderBrowserDialog1->ShowDialog();
System::String ^ Files = folderBrowserDialog1->SelectedPath; 

array<System::String ^> ^ files4 = System::IO::Directory::GetFiles(Files,"*.txt");

this->textBox1->Text = files4;
array<System::String ^> ^ files4 = System::IO::Directory::GetFiles(Files,"*.txt");
if( files4->Length > 0 )
{
  System::String ^ text =  files4[0] ;
  for( int i = 1 ; i < files4.Length ; ++i )
      text += System::Environment::NewLine + files4[i] ;
  this->textBox1->Multiline = true ; // if not multiline
  this->textBox1->WordWrap = false ; // if required
  this->textBox1->Text = text ;
}

This really worked great !!! Big thanks for this. I will look out this logic in detail how it works.

/j

array<System::String ^> ^ files4 = System::IO::Directory::GetFiles(Files,"*.txt");
if( files4->Length > 0 )
{
  System::String ^ text =  files4[0] ;
  for( int i = 1 ; i < files4.Length ; ++i )
      text += System::Environment::NewLine + files4[i] ;
  this->textBox1->Multiline = true ; // if not multiline
  this->textBox1->WordWrap = false ; // if required
  this->textBox1->Text = text ;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.