> and how to write so as not to use std::cin.ignore
1 2
// std::cin.ignore( 10000, '\n' ) ; // throw the new line away
{ std::string discard_this ; std::getline( std::cin, discard_this ) ; } // throw the new line away
#include <iostream>
#include <vector>
#include <string>
usingnamespace std;
int main()
{
vector<string> matrix;
string line;
int maxLineLength = 0;
cout << "Enter some lines (blank line to end)\n";
while ( getline( cin, line ) && line != "" )
{
matrix.push_back( line );
if ( maxLineLength < line.size() ) maxLineLength = line.size();
}
for ( int i = 0; i < maxLineLength; i++ )
{
for ( int j = 0; j < matrix.size(); j++ ) cout << ( i < matrix[j].size() ? matrix[j][i] : ' ' );
cout << endl;
}
}
With apologies to Bob Dylan:
Enter some lines (blank line to end)
How many roads must a man walk down
Before you call him a man
How many seas must a white dove sail
Before she sleeps in the sand
Yes, 'n' how many times must the cannon balls fly
Before they're forever banned
The answer, my friend, is blowin' in the wind
The answer is blowin' in the wind
HBHBYBTT
oeoeeehh
wfwfsfee
o o,o
mrmr raa
aeae'enn
n n n ss
yyys'tww
o h hee
ruseherr
o e oy,
acasw' i
dasl rms
sl emey
lmea b
m upnffl
uhssyoro
sit riw
tm iteei
anivnn
aa med'
wter,
mmhhs i
aaie bin
nnt mas
esun t
w asnbh
a dntele
l od do
k v t ww
e h ii
d e nn
o s 'd
w a c
n i a i
l n n
n
o t
n h
e
b
a w
l i
l n
s d
f
l
y
Nice, a lot of different tricks in this thread. I was hung up on the word matrix, assuming he had something like char** or vector<vector<char>> or vector<string> etc ...