帮我看看错哪了。C++

来源:百度知道 编辑:UC知道 时间:2024/09/28 13:14:14
#include <iostream>
#include <vector>
using namespace std;
int main()
{
string str;
cout << "Enter a string : " << endl;
cin >> str;
size_t i = str.size()+1;
char *p = new char[i];
for(size_t j = 0; j <= i ; ++j){
cout << *p << " ";
++p;
}
delete [] p;
return 0;
}
为什么说第8行错了???

#include <string>
加上就行了,string对>>的重载在这里面.

空格

String 对象称为不可变的(只读),因为一旦创建了该对象,就不能修改该对象的值。看来似乎修改了 String 对象的方法实际上是返回一个包含修改内容的新 String 对象。如果需要修改字符串对象的实际内容,请使用System.Text.StringBuilder 类。

String

好像即使加上
#include <string>
也得不到你想要的结果吧???
你没对p所指向的数组赋值啊~~~

#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
string str;
cout << "Enter a string : " << endl;
cin >> str;
size_t i = str.size()+1;
const char *p;
p=str.c_str();
for(size_t j = 0; j <= i ; ++j){
cout << *p << " ";
++p;
}
return 0;
}