Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

returnin more than one value from a function 1

Status
Not open for further replies.

chineerat

Technical User
Oct 12, 2003
42
0
0
TT
i not too sure if it is possible to do this
eventhough in the followin function it is returning a vector "ret"
i would like to get both "ret" and "pee" values from the split function into the main funtion.

std::vector<int> split( string& s)
{
int pee = 0 ;
int q = 0;
std::vector<int > ret;
typedef string::size_type string_size;
string_size i = 0;
while ( i != s.size() ) {
while ( i != s.size() && isspace(s) )
++i;
string_size j = i;
while ( j != s.size() && !isspace(s[j]) ){
++j;
if ( i != j ) {
stringstream ss(stringstream::in | stringstream::eek:ut);
ss<<s.substr(i, j-1);
ss>>q ;
if( q != 0){
ret.push_back(q);

}
else break;
}}
pee++ ;
i = j;
}
return ret ;
}


int main(){
....code
std::vector<int>words = split(tt) ;
// would get value of "pee" from "split" function
}

THANKS ALOT in ADVANCE
 
It's a bad practice to break/split the thread...
Code:
typedef vector<int> Row;
typedef vector<Row> Matrix;

int GetMatrix(istream& is, Matrix& m)
{
  string s;
  int	n, rows;

  for (rows = 0; getline(is,s); ++rows)
  {
      n = s.find_first_not_of(" \t");
      if (n == eos)
         break;
      {
         istringstream ss(s);
         Row v;
         while (ss >> n)
           v.push_back(n);
         m.push_back(v);
      }
  }
  return rows;
}
Enchance this stub: skip leading empty/blank lines until a real row occurs...
Of course, you may return Matrix from the function (if you wish;)...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top