Please answer me...Okay ?PHP Code:string ** p;
p=new string*[2];
delete [] p;
Thanks a lot
Printable View
Please answer me...Okay ?PHP Code:string ** p;
p=new string*[2];
delete [] p;
Thanks a lot
Yes, but why would you want to allocate pointers to string objects?
Yes.
gg
Thanks gg(codeplug) and CornedBee for your answers...:)
I would like to use 2d array (in my program now, I am using vector of vector) to find the longest string input from user...Quote:
Originally posted by CornedBee
Yes, but why would you want to allocate pointers to string objects?
I am still geting stuck at how to pass my vector-of-vector (2d array) to the function that usually works fine if my argument is something declared as array[10][10], I used vector<vector>array, so now my VC++ compiler tells me that it cannot convert the first parameter of function output(array, count) from (vector<vector<string>,allocate<>.......) into string.
I dont know why it happens and what I should do to fix it ?
Do you know what might be the problem ? How I can pass my parameter more correctly ?
Thanks a lot,
If you are using a "vector of vectors", passing it to a function should be trivial. (It's no different from passing an int for instance)Code:#include <vector>
#include <string>
void Func(const std::vector<std::vector<std::string> >& p_crVectorVector)
{
// Print or whatever here...
}
int main()
{
std::vector<std::vector<std::string> > SomeVector;
// Manipulate SomeVector here...
Func(SomeVector);
return 0;
}
Thanks a lot,Quote:
Originally posted by Assmaster
If you are using a "vector of vectors", passing it to a function should be trivial. (It's no different from passing an int for instance)Code:#include <vector>
#include <string>
void Func(const std::vector<std::vector<std::string> >& p_crVectorVector)
{
// Print or whatever here...
}
int main()
{
std::vector<std::vector<std::string> > SomeVector;
// Manipulate SomeVector here...
Func(SomeVector);
return 0;
}
But the problme is that I copied tha code from the net and it is used for output(array[10][10], n) while i implemented my array as vector of vector, I dont think I can change the whole code into STL because I am bad at programming, and even when I use it, I still dont understand what it content is ? I just know it will output my array and that s all..
<edit>I typed in a hurry and made so many typos</edit>
If your output function takes a 2D array as a parameter, you can't easily pass your vector of vectors to it without doing some conversion.
But if all you need is to print the contents of your vector, I'm in a giving mood today: :)You should easily be able to customize the Print function to suit your needs, as to formatting and whatnot.Code:#pragma warning(disable: 4786)
#include <iostream>
#include <vector>
#include <string>
void Print(const std::vector<std::vector<std::string> >& p_crVectorVector)
{
for(std::vector<std::vector<std::string> >::const_iterator i = p_crVectorVector.begin(); i != p_crVectorVector.end(); i++)
{
for(std::vector<std::string>::const_iterator j = (*i).begin(); j != (*i).end(); j++)
{
std::cout << (*j) << " ";
}
std::cout << std::endl;
}
}
int main()
{
std::vector<std::vector<std::string> > SomeVector;
// Fill the vector with some test data:
SomeVector.resize(2);
SomeVector[0].resize(2);
SomeVector[0][0] = "Some text";
SomeVector[0][1] = "Some more text";
SomeVector[1].resize(1);
SomeVector[1][0] = "Even more text";
// Print it:
Print(SomeVector);
return 0;
}
Okay, I am also in a saying-thanks-to-you mood today :)
Seriously, Thanks so much,
<edit>I forgot a word "mood" and many a dash</edit>
May I ask another question ?
What is #pragma warning(disable: 4786) ???
Why do you have to use it ?
Thanks again
It's there just to disable an irritating warning in VC++ 6.0 that occurs when using some of the STL containters. (Particularily std::map) It might not be needed in this example, but I usually include this line anyway since the warnings may seem somewhat cryptic to people that don't know the reason for them.
If you are using another compiler, you should probably remove this line, though I'm not sure.
Thanks again, :)Quote:
Originally posted by Assmaster
It's there just to disable an irritating warning in VC++ 6.0 that occurs when using some of the STL containters. (Particularily std::map) It might not be needed in this example, but I usually include this line anyway since the warnings may seem somewhat cryptic to people that don't know the reason for them.
This article explains this topic very well.
:thumb: Thanks for that nice link. :)Quote:
I am using DevC++, VC6++, WatCom, MingW(GNU) for windows,