c++ 高手进。 几句代码
来源:百度知道 编辑:UC知道 时间:2024/05/27 13:39:53
看书上的代码。。有这样一段
ostream_iterator <string> oo(cout);
*oo = "Hello, ";
oo++;
*oo = "world!\n";
结果等于 cout<<"Hello world!\n";于是这样写了:
#include <iostream>
#include <string>
using namespace std;
ostream_iterator <string> oo(cout);
void main()
{
*oo = "Hello, ";
oo++;
*oo = "world!\n";
}
但是编译有错误。。想请问下错在什么地方。。该怎么改?
能让他通过编译就行。
ostream_iterator <string> oo(cout);
*oo = "Hello, ";
oo++;
*oo = "world!\n";
结果等于 cout<<"Hello world!\n";于是这样写了:
#include <iostream>
#include <string>
using namespace std;
ostream_iterator <string> oo(cout);
void main()
{
*oo = "Hello, ";
oo++;
*oo = "world!\n";
}
但是编译有错误。。想请问下错在什么地方。。该怎么改?
能让他通过编译就行。
#include <iterator>
这个查查msdn, 需要哪个头文件写的很清楚。。
#include <iostream>
#include <string>
#include <iterator>
using namespace std;
ostream_iterator<string> oo(cout);
int main()
{
*oo = "Hello, ";
// oo++; 这句多余
*oo = "world!\n";
}
这样用
大致意思你已经明白了
#include<iterator>///////////
#include <iostream>
#include <string>
using namespace std;
ostream_iterator <string,char> oo(cout); /////// 第二个参数char你改成“;”你就知道啥意思了
void main()
{
*oo = "Hello, ";
oo++;
*oo = "world!\n";
}
这个是个STL迭代器里面的
头文件要加个#include <iterator>
然后是定义了
ostream_iterator<string> oo(cout);
等价00代表一个输出
至于00++不懂,
因为缺少必要的头文件 <iterator>
#include <iostream>
#include<iterator>
#include <s