The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled C++ Code
Posted by: Jaemyeong Eo | June 16, 2010 @ 3:25am
Revision 1 - Original post on June 16, 2010 @ 2:56am
C++ Code
[
Download
]
#include <iostream> #include <fstream> #include <vector> using namespace std; void flush_left ( vector<string> v1, int width) { ofstream out_file ( "flush_left.txt"); // Outputs the first line, " -----". for ( int i =0; i< width+4; i++) { out_file << "-"; } out_file << endl; int nWidth = width; int new_line = 0; int line_size =0; for ( int i = 0; i < v1.size() ;i++) { line_size = line_size + v1[i].size(); if ( new_line == 0) { out_file << "| " << v1[i]; new_line = 1; } else { if ( line_size + 1 <= nWidth) { out_file << " " << v1[i]; // nWidth = nWidth- v1[i].size(); new_line = 1; line_size++; } else { for ( int j = line_size - v1[i].size(); j < nWidth + 1; j++) { out_file << " "; } out_file << "|" << endl; // nWidth = width; out_file << "| " << v1[i]; line_size = v1[i].size(); new_line = 1; } } } for ( int j = line_size - v1[v1.size() - 1].size(); j < nWidth + 1; j++) { out_file << " "; } out_file << "|" << endl; // nWidth = width; for ( int i =0; i< width+4; i++) { out_file << "-"; } } int main() { cout << " What specified width do you want it " << endl; cout << "to be displayed ? " << endl; int width; cin >> width; ifstream read_file; read_file.open( "file.txt" ); if (!read_file.is_open()) { cout << " File not found " << endl; } vector<string> s_vector; string input_string; while (!read_file.eof()) { read_file >> input_string; s_vector.push_back( input_string); } flush_left ( s_vector, width); return 0; }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.35 / 8
40 Votes