std::string
find_first_of()表示两个字符串中,后一个字符串只要有一个字符满足即成功。
代码如下:
// c++_c.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string src("ikadwji,ajdwkkaqmdjen,skkamopqlnanu.");
cout<<"元音字母为:"<<endl;
size_t cp;
cp = src.find_first_of("aeiou");
int i = 0;
while (cp != string::npos)
{
cout<< src.at(cp) << " ";
cp = src.find_first_of("aeiou", cp+1);
i++;
}
cout<<endl<<i;
system("pause");
return 0;
}
ATL::CString
将字母变大写:
这里要注意输出,代码如下:
// c++_d.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
CString str=_T("abc");
str.MakeUpper();
/*wcout <<(LPCTSTR)str <<endl;*/
wcout<<str.GetString()<<endl;
system("pause");
return 0;
}
提取表达式中的字元
代码如下:
// c++_d.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
CString str(_T("(100 + 200) / 50 - 20 * 8"));
CString token;
int i = 0;
int m = 1;
while (true)
{
token = str.Tokenize(_T(" +-*/()"), i);
if (token == _T(""))
{
break;
}
CString out;
out.Format(_T("token %02d: %s\r\n"), m, token);
_tprintf(out);
/*wcout<<(LPCTSTR)out<<endl;*/
m++;
}
/*wcout <<(LPCTSTR)str <<endl;*/
/*wcout<<str.GetString()<<endl;*/
system("pause");
return 0;
}