【发布时间】:2016-01-11 02:39:44
【问题描述】:
大家好,这是我的代码:
#include <iostream>
#include <string>
using namespace std;
void writeDown(string*t)
{
for (int i = 0; *(t+i)!=NULL; i++)
{
cout << *(t+i) <<endl;
}
}
int main()
{
string t;
getline(cin, t);
string *wsk = &t;
writeDown(wsk);
return 0;
}
所以我只需插入一个字符串,程序应该将cout<< 中的每个字符都放在一个新行中。但这是弹出的内容:
binary '!=' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
我做错了什么?
顺便说一句。我正在为 Win Desktop 使用 VS 2013(顺便说一句。第 2 卷 - 它是 C++ 编码的良好环境吗? - 2015 年了,但在我的笔记本电脑上速度很慢)
【问题讨论】:
-
您似乎正试图将
std::string*视为char*。这不是它的工作原理,它们是非常不同的东西。 -
糟糕,也许吧,那么正确的做法是什么?
-
如果
std::string与const char*类似,那么std::string*与什么类似? -
@Frynio 如果我的回答对您有用,您会愿意将其标记为已接受吗?