F河 发表于 2015-3-17 07:47:54

把string对象中的字符每一行一个输出出来

把string对象中的字符每一行一个输出出来#include<iostream>
#include<string>
using namespace std;
int main()
{

    string str("some string");
    for(auto c : str )
      cout<< c<<endl;
    return 0;
}


雪是梅之香 发表于 2015-3-17 10:48:21

c++?不会啊

ANDES 发表于 2015-3-17 16:23:15

答案是出来了,可是最终还是我学到东西,我也是不会C++的。在校就学会了打个“hello word”,还是两年前的事,我花了20分钟左右,自己百度做出来了,所以希望你能靠自己的能力解决问题,这些简单的问题,百度有很多解答。

#include<iostream>
#include<string>
using namespace std;
int main()
{
        int i = 0;
    string str("some string");
   
        for(i=0;;i++)
        {
        if(str!='\0')
        {
                cout<<str<<endl;
        }
        else
        return 0;
        }
}

F河 发表于 2015-3-17 17:09:49

ANDES 发表于 2015-3-17 16:23
答案是出来了,可是最终还是我学到东西,我也是不会C++的。在校就学会了打个“hello word”,还是两年前的 ...

谢谢你。。不过我要的是auto的使用方法,,其实这一种我也会了,,,,哈哈
页: [1]
查看完整版本: 把string对象中的字符每一行一个输出出来