当前位置: 首页>>代码示例>>C++>>正文


C++ MyString::Write方法代码示例

本文整理汇总了C++中MyString::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ MyString::Write方法的具体用法?C++ MyString::Write怎么用?C++ MyString::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyString的用法示例。


在下文中一共展示了MyString::Write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AnagramsTest

void AnagramsTest(MyString& key, const char* candidatesCStr[], int count)
{
	// Create strings and add them to a vector
    vector<MyString> candidates;    
    for (int i = 0; i < count; i++)
    {
        candidates.push_back(MyString(candidatesCStr[i]));
    }
    
    // Create the output vector and call the anagram finding function
    vector<MyString> output;
    key.GetAnagrams(candidates, output);
    
    // Display each one
    cout << "Anagrams for ";
    key.Write(cout);
    cout << " are:" << endl;
    for (int i = 0; i < output.size(); i++)
    {
        cout << "  ";
        output[i].Write(cout);
        cout << endl;
    }
}
开发者ID:konorati,项目名称:223Projects,代码行数:24,代码来源:main.cpp

示例2: main

int main(int argc, const char* argv[])
{
    MyString str("This is the default string");

	while (true)
	{		
		cout << endl << "Menu" << endl;
		cout << "Current string is: ";
		str.Write(cout);
		cout << endl;
		cout << "1 = Enter a new string to work with" << endl;
		cout << "2 = Find the index of a specific character (IndexOf function)" << endl;
		cout << "3 = Search for a substring (IndexOf function)" << endl;
		cout << "4 = Display a substring (Substring function)" << endl;
		cout << "5 = Split into string array (Split function)" << endl;
        cout << "6 = Anagrams test #1" << endl;
		cout << "7 = Anagrams test #2" << endl;
		cout << "0 = Quit" << endl;

		// Get an option from the user
		string stringSTL;
		getline(cin, stringSTL);

		if ("1" == stringSTL)
		{
			cout << "New string: ";
			getline(cin, stringSTL);
			str.Set(stringSTL.c_str());
			cout << endl;
		}
		else if ("2" == stringSTL)
		{
			cout << "Enter a character to search for: ";
			getline(cin, stringSTL);

			if (stringSTL.length() > 0)
			{
				// Find the starting index and display it
				int index = str.IndexOf(stringSTL.c_str()[0]);
				cout << "Index is: " << index << endl;
			}
		}
		else if ("3" == stringSTL)
		{
			cout << "Enter string to search for: ";
			getline(cin, stringSTL);

			// Find the starting index
			int index = str.IndexOf(stringSTL.c_str());

			cout << "Index is: " << index << endl;
		}
		else if ("4" == stringSTL)
		{
			int startIndex = GetInt("Enter starting index for substring: ");
			int length = GetInt("Enter length for substring: ");
			MyString temp;
			if (str.Substring(startIndex, length, temp))
			{
				cout << "Substring is: ";
				temp.Write(cout);
				cout << endl;
			}
			else
			{
				cout << "Could not get substring, parameters invalid." << endl;
			}
		}
		else if ("5" == stringSTL)
		{
			cout << "Enter a character to use for split: ";
			getline(cin, stringSTL);

			if (stringSTL.length() > 0)
			{
				vector<MyString> strings;
				str.Split(stringSTL.c_str()[0], strings);
				cout << strings.size() << " string(s) returned from split: " << endl;
				for (int i = 0; i < strings.size(); i++)
				{
					cout << "  ";
					strings[i].Write(cout);
					cout << endl;
				}
			}
			else
			{
				cout << "(split operation cancelled)" << endl;
			}
		}
        else if ("6" == stringSTL)
        {
            AnagramsTest1();
        }
		else if ("7" == stringSTL)
        {
            AnagramsTest2();
        }
		else if ("0" == stringSTL)
		{
//.........这里部分代码省略.........
开发者ID:konorati,项目名称:223Projects,代码行数:101,代码来源:main.cpp


注:本文中的MyString::Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。