String Char Iterator [英] String Char Iterator

查看:104
本文介绍了String Char Iterator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚回到C ++编程。
我得到的错误:

Just returned to programming in C++. the errors i get:


发送成员的请求是非类型char [30]

request for member begin in sent is of non-class type char[30]

发送成员的请求是非类型char [30]

request for member end in sent is of non-class type char[30]



char sent[] = "need to break this shiat down";
    for(vector<string>::iterator it=sent.begin(); it!=sent.end(); ++it){
        if(*it == " ")
            cout << "\n";
        else
            cout << *it << endl;
    }

我应该将char更改为字符串还是以不同方式定义向量?

should i change the char to string or define the vector differently?

推荐答案

你也可以使用流媒体来抛出空格并输入换行符。

You can also use streaming to throw out the whitespace and throw in newlines.

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
    stringstream ss("need to break this shiat down.", ios_base::in);

    string s;
    while (ss >> s)
        cout << s << endl;

    return EXIT_SUCCESS;
}

结果:


需要



休息

这个

shiat

down。

need
to
break
this
shiat
down.

这篇关于String Char Iterator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆