我试图通过用户在动态分配的字符串数组中获取值。我试图使用for
/while
-loop这样一种方式,只要用户输入字符串"!"
就可以结束读取字符串。将字符串读入动态分配的数组
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main()
{
int b=1;
int top=0;
string * a=new string[b] ;
cin>>a[b];
top++;
while(a[b]!="!")
{
if(top==b)
b++;
cin>>a[b];
top++;
}
您已经为一个整数分配空间。然后你马上访问结束的元素,然后继续。 – chris
你应该试着问一个问题。 – juanchopanza
+ chris现在查看 –