Pythonchallenge's C + + learning Chapter-03

Source: Internet
Author: User

The second Guanjinghan is a character-handling level

View Web page Source code discovery has a large string of characters to deal with, so many characters are not good if put in the source.

So to use the C + + file operation, the header file used is FStream

Here's a reference to this blog post.

For file processing on the opposite string for character type judgment, the judgment of the individual character type (for example, is a letter or a number) to use a lowercase operator function , these functions in the cctype standard library

The function that determines whether a character is a letter is Isalpha ()

Okay, nonsense, no more, second pass:

Purpose: Reads the string inside the text and handles

Solution:

1# include <iostream>2 //# include <math.h>3# include <string>4# include <fstream>5# include <cctype>6 7 usingSTD::string;8 usingstd::cout;9 //using Std::cin;Ten //using Std::endl; One using namespacestd; A  - intMain () - { theIfstream infile;//definate fstream -     stringTemp//define a var to store strings -  -Infile.open ("MyFile.txt");//Open the file +  -      while(Getline (infile, temp))//Use getline () fuction +     { A          for(inti =0; I < temp.size (); ++i) at         { -             if(Isalpha (Temp[i])) -             { -cout <<Temp[i]; -             } -         } in  -     } to     return 0; +}

The difficulties and solutions encountered:

1. Read the file how to read the inside of each line of string instead of multiple "operator, the answer is to use the while loop and Getline function

2. How do I determine the character category? The answer is to use Cctype.

Pythonchallenge's C + + learning Chapter-03

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.