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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

side by side vector (stl) printing

Status
Not open for further replies.

hedgracer

Programmer
Mar 21, 2001
186
0
0
US
I am trying to print two vectors side by side. The code I am using (actually the fifteeth rendition of this code) is as follows:

for(iterA = B.begin(); iterA != B.end(); iterA++)
for(iter = A.begin(); iter != A.end(); iter++)
{
cout<<*iter<<&quot; &quot;<<*iterA;

}
cout<<endl;

Needless to say this code does not work. I am trying to print the following:

1 20
1 30
1 40

Any help is apprecitated. Thanks in advance.

D. Christman
 
don't use
Code:
for
use a
Code:
while
:
Code:
while ( (iterA !=A.end()) and (iterB !=B.end() )
{
  if (iterA !=A.end())  { cout << iterA; }
  cout << &quot; &quot;;
  if (iterB !=B.end())  { cout << iterB; }
  cout << endl;
  iterA++;
  iterB++;
}
 
OR, useing a for statement....

iRight = iRight.begin();
for(iLeft = iLeft.begin(); iLeft != iLeft.end(); iLeft++)
{
cout << iLeft << &quot; &quot;;
if(iRight != iRight.end()) {
cout << iRight << &quot;\r\n&quot;;
iRight++;
}
}

hope it helped, Rob
&quot;Programming is like art...It makes me feel like chopping my ear off.&quot;

- Currently down
 
oops, forgot code tags...

OR, useing a for statement....

Code:
iRight = iRight.begin();
for(iLeft = iLeft.begin(); iLeft != iLeft.end(); iLeft++)
{
    cout << iLeft << &quot; &quot;;
    if(iRight != iRight.end())  {
        cout << iRight << &quot;\r\n&quot;;
        iRight++;
    }
}
[/code.
hope it helped, Rob
&quot;Programming is like art...It makes me feel like chopping my ear off.&quot;

[URL unfurl="true"]Http://www.thisisrisk.com/[/URL] - Currently down
 
oops, forgot code tags...

OR, useing a for statement....

Code:
iRight = iRight.begin();
for(iLeft = iLeft.begin(); iLeft != iLeft.end(); iLeft++)
{
    cout << iLeft << &quot; &quot;;
    if(iRight != iRight.end())  {
        cout << iRight << &quot;\r\n&quot;;
        iRight++;
    }
}
hope it helped, Rob
&quot;Programming is like art...It makes me feel like chopping my ear off.&quot;

- Currently down
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top