Compare the file suffix

Source: Internet
Author: User

 

# Include <iostream>

Using namespace std;

# Include <string>

# Include <afx. h>

 

CString GetExtName (CString fileName ){

Int pos = fileName. Find ("."); // obtain the. Location

If (pos =-1) {// if not found, this string is directly returned.

Return fileName;

} Else {

Return GetExtName (fileName. Mid (pos + 1); // if it is found, traverse it in depth until the bottom layer

}

}

 

Int main ()

{

While (1)

{

String str;

Cout <"input:" <endl;

Cin> str;

CString tempFileName;

TempFileName. Format ("% s", str. c_str ());

CString tag = GetExtName (tempFileName );

If (tag. Compare ("txt") = 0)

{

Cout <"output:" <"txt" <endl;

}

Else if (tag. Compare ("wmv") = 0)

{

Cout <"output:" <"wmv" <endl;

}

Else if (tag. Compare ("exe") = 0)

{

Cout <"output:" <"exe" <endl;

}

}

 

Return 0;

}

Output:

 

View plain

Input:

11. exe

Output: exe

Input:

11.exe. wmv

Output: wmv

Input:

111.exe.wmv.txt

Output: txt

Lingxiu0613 Column

Related Article

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.