Container vector/file stream ifstream/C ++ usage

Source: Internet
Author: User
Tags uppercase letter
Read a piece of text into a vector object. Each word is stored as an element of a vector. Converts each word in a vector object to an uppercase letter. Output the converted elements in a vector object. Each eight words are output in one row.

# Include "stdafx. H "# include <iostream> # include <fstream> # include <vector> # include <string> using namespace STD; int main () {vector <string> text; string line; string word; string filepath = "C: \ cc.txt"; // ifstream fin (filepath. c_str (); While (! Fin. EOF () {Getline (FIN, line); // read row for (string: size_type I = 0; I <line. size (); ++ I) {If (line [I]> = 'A' & line [I] <= 'Z ') // convert line [I]-= 32; If (line [I] = ''| line [I] = '\ t') {If (! Word. empty () {text. push_back (Word); word = "" ;}} elseword + = line [I];} text. push_back (Word); word = "" ;}// output for (string: size_type I = 0; I! = Text. Size (); ++ I) {cout <text [I] <""; if (I % 7 = 0 & I! = 0) cout <"\ n";} getchar (); Return 0 ;}

[Where do I forget the program. Familiar with container vector/file stream ifstream/C ++ usage]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.