这只是一个基本的打印句子数组字符串。我是 c++ 新手,只使用过 JAVA 和类似的语言,以前从未使用过 c。尝试通过每种不同的排序算法和数据结构来学习它。
但在我开始之前,只测试我的字符串数组会给我一个错误。我不知道为什么它给我一个错误。编译正常实际上运行并打印预期的内容,但如果您正在调试它会崩溃并出现错误。谁能向我解释为什么会这样。尝试size()
并length()
来自 c++ 库,但必须使用 sizeof() '
//BubbleSort.cpp
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
string something[14];
something[0] = "Kate";
something[1] = "likes";
something[2] = "lots";
something[3] = "of";
something[4] = "cake";
something[5] = "in";
something[6] = "her";
something[7] = "mouth";
something[8] = "and";
something[9] = "will";
something[10] = "pay";
something[11] = "a";
something[12] = "lot";
something[13] = "lol";
int some = sizeof(something);
some--;
for (int i = 0; i < some; i++)
{
cout << something[i] << " " ;
}
system("pause");
return 0;
}