I am trying to read words from a file, and print them to another file, but this time I want them to be printed by columns not by rows. Let me show you the code:
Read the file into a vector of strings (one for loop). You'll have to remove the '.'s manually. Then find the length of the longest string (one for loop). Then you have to do
1 2 3 4 5 6 7 8 9 10
vector<string> vec;//all the lines
int len;//longest line
for(int i = 0; i < len; i++){//this is how many lines you want to write
for(int j = 0; j < vec.length(); j++){//for each input line
if(vec.[j].length() > i)//if the line is long enough
cout << vec[j][i];//print the ith char on it
else cout << ' ';
}
cout << '\n';
}
May I ask what does the declaration vector<string> vec do ? I haven't work with such command until now. Also, the length usage doesn't need any other library included ?
Framework you are not welcome to reply on my topic. I knew you as a very good, kind and helpful person. That was like 1 year ago. You were helping me and lots of other people. I dont know what happend to you, but it's easy to tell that something bad happened in your private life. I'm not doctor, nor your friend, so I will stop here. Even if I'm not your friend, I just hope God will help you find the right way... Goodluck.
@jumper007
It creates a vector of strings! I'm guessing you haven't worked with templates yet, so the syntax might be a bit unfamiliar. The following links should help...