64,654
社区成员
发帖
与我相关
我的任务
分享
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
char ch;
vector<char> vCh;
while (cin>>ch && getchar() != '*')
{
vCh.push_back(ch);
}
vector<char>::iterator it;
printf("The element of the vector is: ");
for (it = vCh.begin(); it != vCh.end(); it++)
{
printf("%c ", *it);
}
printf("\n");
system("PAUSE");
return EXIT_SUCCESS;
}
int main()
{
int i = 0,count = 0;
char c,*p = NULL;
while( (c=getchar()) != '\n')
{
++count;
p = (char *)realloc(p,count);
p[i++] = c;
}
p[i] = '\0';
for(i=0; i<(int)strlen(p); ++i)
printf("%c",p[i]);
printf("\n");
return 0;
}