ca48a_demo_c++_for循环语句
作者:互联网
/*ca48a_demo_c++_for循环语句
for(初始化;循环条件;表达式)
for语句头的某些部分可以省略
for语句头中的多个定义
应用程序无法正常启动(0xc000007b) c++问题:
卸载vs2015,安装vs2017,或者vs2019
txwtech
*/
/*ca48a_demo_c++_for循环语句
for(初始化;循环条件;表达式)
for语句头的某些部分可以省略
for语句头中的多个定义
应用程序无法正常启动(0xc000007b) c++问题:
卸载vs2015,安装vs2017,或者vs2019
txwtech
*/
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
for (int i = 0; i < 10; ++i)
cout << i << endl;
vector<string> svec;
svec.push_back("I");
svec.push_back("Love");
svec.push_back("C++");
cout << "输出的结果: " << '"';
//cout << svec[0];
//for (vector<string>::size_type ind = 0; ind != svec.size(); ++ind)
for (int ind = 0; ind != svec.size(); ++ind)
{
cout << svec[ind];
if (ind + 1 != svec.size())//如果不是最后一个,就添加一个空格
cout << " ";
}
cout << '"';
const int size = 12;
int val = 0, ia[size] = { 2,4,6,8,0,1,3,5,7,9,11,12 };
int *pi = ia;
int &ri = val;//声明一个引用
for (int ival = 0; ival != size; ++ival)
{
cout << ia[ival] << "," << ia[ri] << "," << ia[val] << "," << *pi << endl;
++pi;
++ri;
}
//system("pause");
return 0;
}
//
输入1 ,1,2,3,4,5,
输入2:1,2,3
结果:2是输入1的前缀
//习题:6.16
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> ivec1, ivec2;
int ival;
//ivec1.push_back(1);
cout << "Enter elements for this first:(32767 to end)" << endl;
cin >> ival;
while (ival != 32767)
{
//ivec.push_back(ival);
ivec1.push_back(ival);
cin >> ival;
}
cout << "Enter elements for the secon vector:(32767 to end)" << endl;
cin >> ival;
while (ival!=32767)
{
ivec2.push_back(ival);
cin >> ival;
}
vector<int>::size_type size1, size2;
size1= ivec1.size();
size2 = ivec2.size();
bool result = true;
for (vector<int>::size_type ix = 0; ix != (size1 > size2 ? size2 : size1); ++ix)
{
if (ivec1[ix] != ivec2[ix])
{
result = false;
break;
}
}
if (result)
if (size1 < size2)
cout << "the fisrt vector is prefix of the second one" << endl;
else if (size1 == size2)
cout << "two vector are equal" << endl;
else
cout << "the second vector is prefix of the first one" << endl;
else
cout << "No vector is prefix(前缀) of the other one:";
system("pause");
return 0;
}
txwtech 发布了377 篇原创文章 · 获赞 189 · 访问量 90万+ 关注
标签:cout,demo,back,c++,ca48a,ind,push,ival,size 来源: https://blog.csdn.net/txwtech/article/details/104174811