y**i 发帖数: 357 | 1 i want to use old classes in iostream.h , ifstream.h ...
#include
#include
...
cout<<"a";
ifstream s("a");
s.gcount();
...
compile is ok, but link will give error:
Undefined symbol:
cout
gcount
seems this is linker problem, how to tell linker to use iostream? |
|
j*********g 发帖数: 3826 | 2 现在我想用iostream实现一个ostream类,我用的是.net 2005,不会玩也不准备玩C#。
这个ostream需要输出到文件,到console window,以后可能还要有输出到GUI的功能。
2个问题,
1。MFC GUI程序,现在的iostream库里面好像没有stdiostream这个类了,即使VC6有,
我试过AllocConsole,然后没有办法把这个handle和stream挂上。
2。因为我要有若干个输出目标,所以似乎我必须重载这个stream的所有输出函数。好
像很麻烦的样子。
我没怎么用过C++,很土,这里虚心请教,有什么好办法实现这个东西吗? |
|
e***e 发帖数: 38 | 3 【 以下文字转载自 Linux 讨论区 】
【 原文由 exihe 所发表 】
in the c++ head we can use
#include
can anyone tell me where the 'iostream' file is if there is such a file? I can
not find it in /usr/include |
|
s********h 发帖数: 286 | 4 一个很简单的 stream input 小程序,目的是读入名字,ID号码,及其它信息。
我的问题是,如果先读入名字,再读入 ID,就一切正常,可是如果先读入 ID,在读名
字的时候,就会自动跳过,不让我输入名字了。我的程序如下:
#include
using namespace std;
int main()
{
unsigned idNumber;
char firstName[30];
int hoursWorked;
char ch = '\0';
int i = 0;
cout << "Please enter your first name: ";
while (1) {
cin.get(ch);
if (ch == '\n') break;
firstName[i++] = ch;
}
firstName[i] = '\0';
cout << "Please enter your ID Number: ";
cin >> idNumber;
cout |
|
a*******s 发帖数: 324 | 5 you can find it at usr/local/lib/g++-include.
Actually, if you don't remember the place where the file is kept,
find pathname -name "filename" -print
For this case,
find /usr -name "iostream.h" -print
can |
|
t******r 发帖数: 28 | 6 1. What is Visual C++?
a.It's a program used for starting other programs.
b.It's a program that you use to create other programs.
c.It's a program for browsing the Web.
d.It's a multimedia program that teaches you how to program.
2.What is the name of the process by which Visual C++ converts your C++
code to a program the computer can understand?
a.Compile.
b.Run.
c.Debug.
d.Build.
3.What do you call the container that stores all the files you write and
all the files Visual C++ writes to create ... 阅读全帖 |
|
t******r 发帖数: 28 | 7 1. What is Visual C++?
a.It's a program used for starting other programs.
b.It's a program that you use to create other programs.
c.It's a program for browsing the Web.
d.It's a multimedia program that teaches you how to program.
2.What is the name of the process by which Visual C++ converts your C++
code to a program the computer can understand?
a.Compile.
b.Run.
c.Debug.
d.Build.
3.What do you call the container that stores all the files you write and
all the files Visual C++ writes to create ... 阅读全帖 |
|
e********r 发帖数: 2352 | 8 在本地的考试中心预约的上机考试。考试有三个部分,1.数学题,2.给出一种新的编程
语言的语法,回答相应问题,3. Programming Test 要求速度和准确性both important
Programming test 答得不好,肯定不行了,把面试题发上来让大家做做。做了3个半小
时,快累死了。
数学题基本上就是脑筋急转弯,举几个例子
1. You have three kinds of magazines, all but two are Times, all but two are
Science, all but two are Nature. How many magazines in total do you have?
3 books
2. Only one of the answers is true
A. All of the below are true
B. All answers are true
C. One of the above is true
D. All of the above are true
E. None of the above ar... 阅读全帖 |
|
x******a 发帖数: 6336 | 9 I got thousands problems on the following piece of code "dumpfile.h" when I
compile under cygwin. it is ok under visual stduio... can anyone help?
Thanks!
#include
#include
#include //ostream_iterator
#include //cerr
#include //std::copy
template
void dump_to_file(const char* filename, const std::vector& v_d){
std::ofstream ofs(filename);
if(!ofs){
std::cerr<<"Unable to open the file to write!n";
return ;... 阅读全帖 |
|
c********2 发帖数: 56 | 10 面的是Associate C++ Developer,下面是面试题,光顾着记题了,最后只有56%的通过
率,要到
80%才能ONSITE,算是帮大家做点贡献吧,他家在招人,赶快去投简历
1) #include
using namespace std;
struct A{
A(int value) : m_value(value){}
int m_value;
};
struct B:A {
B(int value):A(value){}
};
int main(){
try {
try{
throw B(5);
}
catch(A a){
a.m_value *=2;
throw;
}
catch(B b){
b.m_value -=2;
throw b;
}
}
catch(A a){
... 阅读全帖 |
|
r*******y 发帖数: 290 | 11 you can use iostream to do serialization
Define three classes: Serializer, Deserializer, and Serializable
class Serializer
{
define insert or >> for primitive types
use an iostream to hold data
}
class Deserializer
{
define restore or << for primitive types
use an iostream to hold the received buffer
}
class Serializable
{
define Serialize(Serializer& ser) and deserialize(Deserializer& deser)
define actual data to serialize or deserialize
}
You can define the above three |
|
a****d 发帖数: 114 | 12 下面这个程序为什么选择的是template version呢?
/******** 程序1 ********/
#include
using namespace std;
#include
using namespace std;
template
void f(const T a) {
cout<<"Template version."<
}
void f(const int* a) {
cout<<"Plain version."<
}
int main() {
int x=2;
int *a= &x;
f(a);
return 0;
}
/************************/
但是把所有的 int* 换成 int 之后选的是non-template version:
/********* 程序2 ************/
#include
using namespace std;
template
void f(const |
|
r*******y 发帖数: 1081 | 13 //1.cpp
#include
// using namespace std;
int main(){cout<<1;}
this file can not be compiled since cout is not declared in this scope.
I read the header file iostream and find a declare for cout:
extern ostream cout;
It seems cout is declared in the header file iostream, but
why we also need to write down
using namespace std; ?
thanks. |
|
g***l 发帖数: 2753 | 14 老大的这个方法是可行的。可是又出现新的问题了。
我定义了如下接口:
template
dec_base* new_object()
{
return new T;
}
typedef dec_base* (*ObjectGenerator)();
static std::map generator_map;
template
void register_dec_handle(int tag_id)
{
generator_map.insert(make_pair(tag_id,new_object));
}
如果把以上代码跟 main() 代码放在一个main.cpp里面,编译链接都没有问题。但是如
果把以上代码放在另外一个单独的sample.cpp里面,在另外一个main.cpp中的main()调用
register_dec_handle()的时间,gcc就会报告
g++ main.cpp sample.cpp -o sample.exe
main.cpp: 在函数‘int main(... 阅读全帖 |
|
d*******2 发帖数: 340 | 15 我的问题是直接用./file的话可以输出结果,但是程序在一两天之后就停了(可能是负
责IT的人停的)。但是把./file放到file.sh里面再用qsub file就没有数据输出。下面
三个文件都试过了,请问错误在什么地方?
先谢了!
#include
#include
using namespace std;
int main(int argc, char* argv[])
{
ofstream file;
file.open("output");
int k=100;
file << "k:" << k <
file.close();
return 0;
}
#include
#include
using namespace std;
int main()
{
int k=100;
cout << "k:" << k;
}
#include
using namespace std;
int main(int argc, char* a |
|
r*******y 发帖数: 1081 | 16 【 以下文字转载自 Programming 讨论区 】
发信人: romancity (山顶一枝草), 信区: Programming
标 题: c++ class definition
发信站: BBS 未名空间站 (Mon Mar 7 23:24:44 2011, 美东)
is this definition local to a file ? for example
// file 1.cpp
#include
using namespace std;
class mytest{
int i;
}
int main(){
return 0;
}
// file 2.cpp
#include
using namespace std;
class mytest{
int i;
}
Then I compile g++ -o 1 1.cpp 2.cpp
it is ok. So I just think that class definition should be
local t... 阅读全帖 |
|
j***y 发帖数: 2074 | 17 从网上抄了一段源代码:
---
#include
#include |
|
l*********y 发帖数: 142 | 18 #include
#include
#include
#include
#include
#include
#include
using namespace std;
class Counter {
public :
Counter() {
counter = 0;
}
void increment() {
counter++;
}
void decrement() {
counter --;
}
int getValue() {
return counter;
}
private:
int counter;
};
class COWString {
public:
COWString() {
pointer = NULL;
rc = new Counter();
}... 阅读全帖 |
|
h*****g 发帖数: 312 | 19 感觉挺简单的,不知道我的理解是否对
#include
#include
#include
#include
#include |
|
h*****g 发帖数: 312 | 20 感觉挺简单的,不知道我的理解是否对
#include
#include
#include
#include
#include |
|
h*****g 发帖数: 312 | 21 感觉挺简单的,不知道我的理解是否对
#include
#include
#include
#include
#include |
|
h*****g 发帖数: 312 | 22 感觉挺简单的,不知道我的理解是否对
#include
#include
#include
#include
#include |
|
x******a 发帖数: 6336 | 23 //main()
#include
#include
#include "linkedlist.h"
int main()
{
LinkedList myList(5, "luke");
Iterator myIterator=myList.begin();
myList.insert(myIterator, "leia");
myIterator.forward();
myList.erase(myIterator);
myList.insert(myIterator, "chewbca"); 《======出问题。
myList[2]="han";
for (int i=0; i
std::cout<
}
myList.insert(myIterator, "chewbca"); 《======出问题。
这一句运行起来ta... 阅读全帖 |
|
j******x 发帖数: 383 | 24 有人用过dcmtk吗?我在linux下用g++ 编译以后,用一个范例程序测试,编译的时候显
示:
In file included from /usr/local/include/dcmtk/ofstd/ofstring.h:65,
from /usr/local/include/dcmtk/oflog/tstring.h:27,
from /usr/local/include/dcmtk/oflog/streams.h:27,
from /usr/local/include/dcmtk/oflog/loglevel.h:29,
from /usr/local/include/dcmtk/oflog/logger.h:28,
from /usr/local/include/dcmtk/oflog/oflog.h:35,
from /usr/local/include/dcmtk/dcmdata/d... 阅读全帖 |
|
j**********i 发帖数: 3758 | 25 http://baike.baidu.com/view/3691487.htm
#include
#include
#include
#include
#include
#include
int main()
{
float m_fTimeElapsed;
int j;
long double x;
LARGE_INTEGER m_timeFreq;
LARGE_INTEGER m_timeStart;
LARGE_INTEGER m_timeStop;
QueryPerformanceFrequency(&m_timeFreq);
QueryPerformanceCounter(&m_timeStart);
for(int i=0;i<4000000000;i++){
j=i+1;
// x=(long double)sin(i*3... 阅读全帖 |
|
j******x 发帖数: 383 | 26 【 以下文字转载自 Software 讨论区 】
发信人: jackalex (峰之砂), 信区: Software
标 题: about dcmtk (转载)
发信站: BBS 未名空间站 (Tue Apr 12 14:48:51 2011, 美东)
发信人: jackalex (峰之砂), 信区: CS
标 题: about dcmtk
发信站: BBS 未名空间站 (Tue Apr 12 14:48:27 2011, 美东)
有人用过dcmtk吗?我在linux下用g++ 编译以后,用一个范例程序测试,编译的时候显
示:
In file included from /usr/local/include/dcmtk/ofstd/ofstring.h:65,
from /usr/local/include/dcmtk/oflog/tstring.h:27,
from /usr/local/include/dcmtk/oflog/streams.h:27,
from /usr/local... 阅读全帖 |
|
F*******i 发帖数: 190 | 27 Daxia,
any suggestions for the lib/tools to process the .gz file while has the same
interface as std::iostream?
does boost:iostreams do the job?
many thanks |
|
k***e 发帖数: 7933 | 28 I installed xercesc package so that I
can handle xml in C++. I am using vs.net 2003
as my IDE. I downloaded the binary release from
http://xml.apache.org/xerces-c/download.cgi
However I am having problem to get it work.
Here is the simple test code:
#include
#include
#include
#if defined(XERCES_NEW_IOSTREAMS)
#include
#else
#include
#endif
#include
X |
|
s*****n 发帖数: 1279 | 29 以前用C++都是在interpreter的环境下,现在想编译,发现好多都不懂。大家帮我看看下
面这个程序:
#include
#include
#include
#include
#include
int main (int argc, char **argv)
{
int iarg = 1;
char root_file_name[256];
strcpy (single_file_name,argv[1]);
strcpy (root_file_name, argv[2]);
ofstream decayresults(root_file_name);
decayresults.close();
cout<<"That's all"<
}//end of main
然后我用下面的Makefile编译总是通不过,说是ofstream,cout, endl 都没有定义。难
道不是只要include , |
|
o******r 发帖数: 259 | 30 以下程序似乎是对的,在Visual Studio 2005里面却报错:
error C2660: 'B::Add' : function does not take 1 arguments
#include
using namespace std;
class A
{
public:
int Add(int X) {return Add(X, 1);};
private:
virtual int Add(int X, int Y) {return X+Y;};
};
class B: public A
{
private:
int Add(int X, int Y) {return X-Y;};
};
int main()
{
B Obj;
cout << Obj.Add(5);
return 0;
}
难道B不能用base clas A的那个public function吗?
用不同函数名就没问题了
#include
using namespac |
|
P*****f 发帖数: 2272 | 31 name hiding
以下程序似乎是对的,在Visual Studio 2005里面却报错:
error C2660: 'B::Add' : function does not take 1 arguments
#include
using namespace std;
class A
{
public:
int Add(int X) {return Add(X, 1);};
private:
virtual int Add(int X, int Y) {return X+Y;};
};
class B: public A
{
private:
int Add(int X, int Y) {return X-Y;};
};
int main()
{
B Obj;
cout << Obj.Add(5);
return 0;
}
难道B不能用base clas A的那个public function吗?
用不同函数名就没问题了
#include
u |
|
r******2 发帖数: 754 | 32 大家好,
这个指针真是麻烦。有点想不明白。
我知道删除单个指针要用delete,而是数组的话,要用delete [] theArray。
但是为什么不能一个接个的delete呢,既然所有的数组都在heap上。
比如,
#include
int main()
{
int * Family = new int[5];
delete [] Family;
}
这是标准的方法。但为什么以下的方法就不行?Family+i 也是一个指针, 并且就是在
heap上呀,
#include
int main()
{
int * Family = new int[5];
for (int i=0; i<5; i++)
delete (Family+i);
}
有什么猫腻呀? 请大侠指点! |
|
b**n 发帖数: 289 | 33 Right, Thanks a lot.
The following code is OK:
#include
using std::string;
int main(){
string str = "string";
return 0;
}
The following one is NOT OK:
using std::string;
int main(){
string str = "string";
return 0;
}
I guess header file somehow already included . I am not
sure about this.
Thanks a lot. |
|
R********n 发帖数: 3601 | 34 我在VS下面用
#include
就可以用strcmp() strcat()等等命令。难道不用include 么?还是说
iostream已经包括了? |
|
h**o 发帖数: 347 | 35 1. 现在有AB两个类,由于AB的constructor比较大,又只有f()不相同
我想在初始化B的时候实现动态绑定,请问怎么样可以实现?不成功的代码如下
#include
using namespace std;
class A{
public:
A() { f(); }
virtual void f() { cout << "As class A" << endl; }
};
class B: public A{
public:
B():A() { }
virtual void f() { cout << "As class B" << endl; }
};
int main()
{
B b;
return 0;
}
输出结果为As class A
2. 这个我不太清楚是不是compiler的问题还是什么特别规则,感觉非常奇怪
#include
using namespace std;
class A{
public:
virtual void f() { cout << "As class A" << end |
|
c***d 发帖数: 996 | 36 ☆─────────────────────────────────────☆
chamberlain (PKU|PHY01|面朝大海|春暖花开) 于 (Mon Jul 2 18:07:20 2007) 提到:
(c++)为什么不能把这个function的definition放到class里面?
一个很简单的class,如下,编译可以通过
#include
using namespace std;
class Apple{
public:
void print();//declaration
};
void Apple::print() {
cout<<"I am an apple"<
}
但是如果把print()的definition部分挪到class里面去,如下,为什么就不行了呢?
#include
using namespace std;
class Apple{
public:
void print();//declaration
|
|
f********a 发帖数: 1109 | 37 有一段代码vector.h和vector.cc
[CODE]//vector.h
int add(int x, int y);
//vector.cc
#include
int add(int x, int y){
return (x+y);
}
int main(){
std::cout<
return 0;
}
[/CODE]
显然我不需要include "vector.h"就可以编译成功。因为编译器自动会找vector.h
但是当我用了namespace以后:
[CODE]//vector.h
namespace TEST{
int add(int x, int y);
}
//vector.cc
#include
#include "vector.h"
int TEST::add(int x, int y){
return (x+y);
}
int main(){
std::cout<
retur |
|
h*******n 发帖数: 2052 | 38 很简单一个程序:
#include
using namespace std;
int main()
{
int a=2;
//cin>>a;
cout<
cin.get();
return 0;
}
这里cin.get();的作用是让屏幕保持原来的状态以便看到a的输出值。(我用的是Dev-C
++)
如果改成
#include
using namespace std;
int main()
{
int a;
cin>>a;
cout<
cin.get();
return 0;
}
cin.get();就不work了, 程序直接就返回了, 没有在cin.get()处等待。 据说是因为
前面有一个cin语句。 |
|
b***y 发帖数: 2799 | 39 ☆─────────────────────────────────────☆
wenchang (随缘@菩提树下,拈花一笑@求道...) 于 (Sun Sep 25 19:33:16 2005) 提到:
how can we make the output of
#include
main(){
cout<<"hello world"<
}
as the following:
initialize
hello world
clean up
without changing the main program.
☆─────────────────────────────────────☆
acrof (KoKo) 于 (Sun Sep 25 19:58:06 2005) 提到:
#include
class A
{
public:
A()
{
cout<<"initialize"<
}
~A()
{
cout<<"clean up"<
}
} |
|
z****e 发帖数: 2024 | 40 试试这个。
#include
using namespace std;
int main(int argc, char* argv[])
{
char ca2[]={'c','+','+','\0'};
char* ip=ca2;
cout<
cout<
return 0;
}
我感觉是iostream里面对运算符<<的重载导致的。 |
|
r*******y 发帖数: 1081 | 41 is this definition local to a file ? for example
// file 1.cpp
#include
using namespace std;
class mytest{
int i;
}
int main(){
return 0;
}
// file 2.cpp
#include
using namespace std;
class mytest{
int i;
}
Then I compile g++ -o 1 1.cpp 2.cpp
it is ok. So I just think that class definition should be
local to the file, or otherwise there should be
multidefinition error in this example, right ? Thanks. |
|
r****t 发帖数: 10904 | 42 But the linking works even when I made two definition of class to be
different:
//1.cpp
#include
using namespace std;
class mytest{
int i;
};
int main(){
return 0;
}
//2.cpp
#include
using namespace std;
class mytest{
float a1;
float a2;
};
$ g++ -o a.out 1.cpp 2.cpp
这个跟 standard 3.2.5 说的不一样 (each definition of D shall consist of the
same sequence of tokens;) 这个是仲么回事? |
|
r*******y 发帖数: 1081 | 43 The code below is OK
//4.cpp
#include
using namespace std;
class M{
int i;
public:
M(){cout << "default constructor" << endl;}
M(int ii):i(ii){cout << "constructor"<< endl;}
M(const M & mm):i(mm.i){cout << "copy constructor"<
};
int main(){
M mm = 1;
}
If I run the program, output is
constructor
But If I changed the copy constructor as
M(M & mm):i(mm.i){cout << "copy constructor"<
that is, the parameter is M & instead of const M&
N... 阅读全帖 |
|
F*******i 发帖数: 190 | 44 Daxia,
any suggestions for the lib/tools to process the .gz file while has the same
interface as std::iostream?
does boost:iostreams do the job?
many thanks |
|
t****t 发帖数: 6806 | 45 if you want to use iostream and stl (BTW iostream is a part of stl), you don
't have to be jin tong. jin tong is for library writer who want to extend
the library. normal user just call functions. |
|
t****t 发帖数: 6806 | 46 OK, solved. let me explain this, this is complex.
you called copy(....begin(), ....end(), ostream_iterator<...>(...)), so
ostream_iterator will do the << for you. naturally, ostream_iterator is
within namespace std, so operator<< is called in namespace std.
Now for overload resolution. there are a lot of operator<< within namespace
std; so these are considered. your parameters to operator<< are std::basic_
ostream<...> and std::pair<...>, they are both in namespace std. Therefore
no other namesp... 阅读全帖 |
|
r**a 发帖数: 536 | 47 我试了试下面两个code,第一个比我原来贴的那个速度明显快了但是还是比不上第二个。
Code1:
#include
#include
using namespace std;
class A
{
public:
A(const size_t N): _N(N) {}
vector > getXY()
{
//vector xytemp;
//for (size_t i = 0; i != 2; ++i)
// xytemp.push_back(i+3);
vector > xy(_N);
for (size_t i = 0; i != _N; ++i)
for (size_t j = 0; j != 2; ++j)
xy[i].push_back(j+3... 阅读全帖 |
|
j******x 发帖数: 383 | 48 【 以下文字转载自 CS 讨论区 】
发信人: jackalex (峰之砂), 信区: CS
标 题: about dcmtk
发信站: BBS 未名空间站 (Tue Apr 12 14:48:27 2011, 美东)
有人用过dcmtk吗?我在linux下用g++ 编译以后,用一个范例程序测试,编译的时候显
示:
In file included from /usr/local/include/dcmtk/ofstd/ofstring.h:65,
from /usr/local/include/dcmtk/oflog/tstring.h:27,
from /usr/local/include/dcmtk/oflog/streams.h:27,
from /usr/local/include/dcmtk/oflog/loglevel.h:29,
from /usr/local/include/dcmtk/oflog/logger.h:28,
... 阅读全帖 |
|
a****s 发帖数: 2060 | 49 转
#include
#include
#include
#include
void main()
{
int a=0,b=0,c=0;
int A=0,B=0,C=0;
int num=0;
while(1)
{
while(A+b==3 && B+a==1 && A+c==6 && C+a==4 && C+b==7)
{
cout<
cout<
cout<
cout<
cout<
cout<
return;
}
a=rand()%10;
b=rand()%10;
c=rand()%10;
A=rand()%10;
B=rand()%10;
C=rand()%10;
}
} |
|
O******5 发帖数: 483 | 50 #include
using namespace std;
int main(){
cout <<"Hello,SB!" << endl;
} |
|