Error cin is not a member of std

  • Forum
  • Beginners
  • std::cin and std::cout isn’t working

std::cin and std::cout isn’t working

Hello all
the std::cin and std::cout aren’t working for me correctly :(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include <iostream>
#include "stdafx.h"
int main(){
	int count(0);
	double total (0.0);
	while(true){
		std::string
		std::cout <<"Next value please; ";
		double value;
		std::cin >> value;
		if(value > 9999.0)break;
		++count;
		total += value;
	}
	std::cout << "nYou input " << count << " values. n";
	std::cout << "Theur total is " << total  <<".n";
	std::cout << "the arithmetic mean (average) of those values is " <<
		total/count << ".n";
	return 0;
}

what could the reason be?
Thanks

What is line 7 std::string ? It looks as though it should not be there at all.

it also isn’t working without string

Could you please give a more precise description than «it isn’t working». What is the actual problem?

when I got to debug it says error — I am using visual studio 2010.
the thing I got is:

1>—— Build started: Project: Testing, Configuration: Debug Win32 ——
1> Testing.cpp
1>Testing.cpp(2): warning C4627: ‘#include <iostream>’: skipped when looking for precompiled header use
1> Add directive to ‘StdAfx.h’ or rebuild precompiled header
1>Testing.cpp(8): error C2039: ‘cout’ : is not a member of ‘std’
1>Testing.cpp(8): error C2065: ‘cout’ : undeclared identifier
1>Testing.cpp(10): error C2039: ‘cin’ : is not a member of ‘std’
1>Testing.cpp(10): error C2065: ‘cin’ : undeclared identifier
1>Testing.cpp(15): error C2039: ‘cout’ : is not a member of ‘std’
1>Testing.cpp(15): error C2065: ‘cout’ : undeclared identifier
1>Testing.cpp(16): error C2039: ‘cout’ : is not a member of ‘std’
1>Testing.cpp(16): error C2065: ‘cout’ : undeclared identifier
1>Testing.cpp(17): error C2039: ‘cout’ : is not a member of ‘std’
1>Testing.cpp(17): error C2065: ‘cout’ : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

For some reason the iostream library which contains the definitions for std::cin and std::cout is not being included. That is your prolbem.

how do I include it?

try removing the spaces before the «#include <iostream>»
first line of the thing you posted
#include <iostream>

I suspect it is something to do with #include "stdafx.h" whuich isn’t standard c++, rather it is specific to some compilers.

Beyond that, sorry, I can’t help, though I’m sure someone else should be able to.

If you’re using precompiled headers, #include "stdafx.h" must come before any other includes.

You set up your project to use precompiled headers which is what stdafx.h is for.

1. Create a new project.
2. In the first dialog box select console application.
3. In the next dialog box do not click Finish to accept the current settings. Instead click Next.
4. In the following dialog box deselect Precompiled header, then select Empty project. Make sure you deselect Precompiled header before selecting Empty project, otherwise Precompiled header will be still selected but dimmed out.
5. Now click Ok.
6. Add a new cpp file to your new project and copy and paste in your old code.
7. Remove the lines:

#include "stdafx.h"

std::string

thanx, now working :)

Topic archived. No new replies allowed.

I was working on a question to pass cin as an argument, here is my code:

#include<istream>
#include<iostream>

void fun(std::istream &os)
{
    int i;
    os>>i;
    std::cout<<i<<std::endl;
}

int main()
{
    fun(std::istream::cin);  //ERROR

    return 0;
}

The error says:

‘cin’ is not a member of ‘std::istream’ {aka ‘std::basic_istream’}

The error went away when it was made just std::cin — now it is written in book (CPP Primer) that cin is a istream object but the constructor for istream requires a reference to stream buffer object in order to be constructed. So how does cin just works without any argument? example:

cin>>input;

asked Mar 16, 2020 at 20:22

Agrudge Amicus's user avatar

0

std::cin is an object whose type is std::istream. Its name is std::cin. It’s not a member of std::istream, so you can’t name it as if it were. That’s why the compiler complains about std::istream::cin.

answered Mar 16, 2020 at 20:33

Pete Becker's user avatar

Pete BeckerPete Becker

74k8 gold badges75 silver badges163 bronze badges

Here’s my beginner’s code.

#include «make polygon.h»

#include «stdio.h»

using name space std;

int main(int argc, char* argv[])

{

std::cout<<(«Hello World!»);

char MyLine[100];

std::cin.getline(MyLine,100);

return 0;

}

And here is my build error(s)… ! :

1>—— Build started: Project: Make Polygon, Configuration: Debug Win32 ——

1>  make polygon.cpp

1>c:userswindowsdocumentsvisual studio 2010projectsmake polygonmake polygonmake polygon.cpp(3): error C2146: syntax error : missing ‘;’ before identifier ‘space’

1>c:userswindowsdocumentsvisual studio 2010projectsmake polygonmake polygonmake polygon.cpp(3): error C2873: ‘name’ : symbol cannot be used in a using-declaration

1>c:userswindowsdocumentsvisual studio 2010projectsmake polygonmake polygonmake polygon.cpp(3): error C2146: syntax error : missing ‘;’ before identifier ‘std’

1>c:userswindowsdocumentsvisual studio 2010projectsmake polygonmake polygonmake polygon.cpp(3): error C4430: missing type specifier — int assumed. Note: C++ does not support default-int

1>c:userswindowsdocumentsvisual studio 2010projectsmake polygonmake polygonmake polygon.cpp(3): error C4430: missing type specifier — int assumed. Note: C++ does not support default-int

1>c:userswindowsdocumentsvisual studio 2010projectsmake polygonmake polygonmake polygon.cpp(3): error C2365: ‘std’ : redefinition; previous definition was ‘namespace’

1>c:userswindowsdocumentsvisual studio 2010projectsmake polygonmake polygonmake polygon.cpp(7): error C2039: ‘cout’ : is not a member of ‘std’

1>c:userswindowsdocumentsvisual studio 2010projectsmake polygonmake polygonmake polygon.cpp(7): error C2065: ‘cout’ : undeclared identifier

1>c:userswindowsdocumentsvisual studio 2010projectsmake polygonmake polygonmake polygon.cpp(9): error C2039: ‘cin’ : is not a member of ‘std’

1>c:userswindowsdocumentsvisual studio 2010projectsmake polygonmake polygonmake polygon.cpp(9): error C2065: ‘cin’ : undeclared identifier

1>c:userswindowsdocumentsvisual studio 2010projectsmake polygonmake polygonmake polygon.cpp(9): error C2228: left of ‘.getline’ must have class/struct/union

Have I got to add something to get this to work?

compiling with C++ source and got the following erros inside iostream

«/export/home/opt/SUNWspro/prod/include/CC/Cstd/./istream», line 41: Error: Use «;» to terminate declarations.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 4: Error: istream is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 5: Error: cin is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 6: Error: ws is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 9: Error: ostream is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 10: Error: cout is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 11: Error: cerr is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 12: Error: clog is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 14: Error: ios is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 15: Error: iostream is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 16: Error: streambuf is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 20: Error: endl is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 21: Error: ends is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 22: Error: flush is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 23: Error: streamsize is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 24: Error: streampos is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 25: Error: unitbuf is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 26: Error: nounitbuf is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 27: Error: boolalpha is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 28: Error: noboolalpha is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 29: Error: showbase is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 30: Error: noshowbase is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 31: Error: showpoint is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 32: Error: noshowpoint is not a member of std::std::std.
«/export/home/opt/SUNWspro/prod/include/CC/Cstd/iostream.h», line 33: Error: showpos is not a member of std::std::std.
Compilation aborted, too many Error messages.
*** Error code 1

My system is:
sol-10-u5-ga-x86
SunStudio12ml-solaris-x86-200709-pkg.tar.bz2
No patch

can anyone figure out what this mean ?

Edited by: Harry-Potter on Jun 24, 2008 8:20 PM

Edited by: Harry-Potter on Jun 25, 2008 12:52 AM

Edited by: Harry-Potter on Jun 25, 2008 12:55 AM

Edited by: Harry-Potter on Jun 25, 2008 12:55 AM

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
// sstream standard header
#pragma once
#ifndef _SSTREAM_
#define _SSTREAM_
#ifndef RC_INVOKED
#include <string>
 
#ifdef _MSC_VER
 #pragma pack(push,_CRT_PACKING)
 #pragma warning(push,3)
#endif  /* _MSC_VER */
 
_STD_BEGIN
 
  #pragma warning(disable:4251)
 
        // TEMPLATE CLASS basic_stringbuf
template<class _Elem,
    class _Traits,
    class _Alloc>
    class basic_stringbuf
        : public basic_streambuf<_Elem, _Traits>
    {   // stream buffer maintaining an allocated character array
public:
    typedef _Alloc allocator_type;
    typedef basic_streambuf<_Elem, _Traits> _Mysb;
    typedef basic_string<_Elem, _Traits, _Alloc> _Mystr;
 
    explicit __CLR_OR_THIS_CALL basic_stringbuf(ios_base::openmode _Mode =
        ios_base::in | ios_base::out)
        {   // construct empty character buffer from mode
        _Init(0, 0, _Getstate(_Mode));
        }
 
    explicit __CLR_OR_THIS_CALL basic_stringbuf(const _Mystr& _Str,
        ios_base::openmode _Mode = ios_base::in | ios_base::out)
        {   // construct character buffer from string, mode
        _Init(_Str.c_str(), _Str.size(), _Getstate(_Mode));
        }
 
    virtual __CLR_OR_THIS_CALL ~basic_stringbuf()
        {   // destroy the object
        _Tidy();
        }
 
    enum
        {   // constants for bits in stream state
        _Allocated = 1, // set if character array storage has been allocated
        _Constant = 2// set if character array nonmutable
        _Noread = 4,    // set if character array cannot be read
        _Append = 8,    // set if all writes are appends
        _Atend = 16};   // set if initial writes are appends
    typedef int _Strstate;
 
    typedef typename _Traits::int_type int_type;
    typedef typename _Traits::pos_type pos_type;
    typedef typename _Traits::off_type off_type;
 
    _Mystr __CLR_OR_THIS_CALL str() const
        {   // return string copy of character array
        if (!(_Mystate & _Constant) && _Mysb::pptr() != 0)
            {   // writable, make string from write buffer
            _Mystr _Str(_Mysb::pbase(), (_Seekhigh < _Mysb::pptr()
                ? _Mysb::pptr() : _Seekhigh) - _Mysb::pbase());
            return (_Str);
            }
        else if (!(_Mystate & _Noread) && _Mysb::gptr() != 0)
            {   // readable, make string from read buffer
            _Mystr _Str(_Mysb::eback(), _Mysb::egptr() - _Mysb::eback());
            return (_Str);
            }
        else
            {   // inaccessible, return empty string
            _Mystr _Nul;
            return (_Nul);
            }
        }
 
    void __CLR_OR_THIS_CALL str(const _Mystr& _Newstr)
        {   // replace character array from string
        _Tidy();
        _Init(_Newstr.c_str(), _Newstr.size(), _Mystate);
        }
 
protected:
    virtual int_type __CLR_OR_THIS_CALL overflow(int_type _Meta = _Traits::eof())
        {   // put an element to stream
        if (_Mystate & _Append
            && _Mysb::pptr() != 0 && _Mysb::pptr() < _Seekhigh)
            _Mysb::setp(_Mysb::pbase(), _Seekhigh, _Mysb::epptr());
 
        if (_Traits::eq_int_type(_Traits::eof(), _Meta))
            return (_Traits::not_eof(_Meta));   // EOF, return success code
        else if (_Mysb::pptr() != 0
            && _Mysb::pptr() < _Mysb::epptr())
            {   // room in buffer, store it
            *_Mysb::_Pninc() = _Traits::to_char_type(_Meta);
            return (_Meta);
            }
        else if (_Mystate & _Constant)
            return (_Traits::eof());    // array nonmutable, fail
        else
            {   // grow buffer and store element
            size_t _Oldsize = _Mysb::pptr() == 0
                ? 0 : _Mysb::epptr() - _Mysb::eback();
            size_t _Newsize = _Oldsize;
            size_t _Inc = _Newsize / 2 < _MINSIZE
                ? _MINSIZE : _Newsize / 2;  // grow by 50 per cent
            _Elem *_Newptr = 0;
            _Elem *_Oldptr = _Mysb::eback();
 
            while (0 < _Inc && INT_MAX - _Inc < _Newsize)
                _Inc /= 2;  // increment causes overflow, halve it
            if (0 < _Inc)
                {   // finite increment, allocate new character array
                _Newsize += _Inc;
                _Newptr = _Al.allocate(_Newsize);
                }
 
            if (0 < _Oldsize)
                _Traits_helper::copy_s<_Traits>(_Newptr, _Newsize, _Oldptr, _Oldsize);
 
            if (_Oldsize == 0)
                {   // first growth, set up pointers
                _Seekhigh = _Newptr;
                _Mysb::setp(_Newptr, _Newptr + _Newsize);
                if (_Mystate & _Noread)
                    _Mysb::setg(_Newptr, 0, _Newptr);
                else
                    _Mysb::setg(_Newptr, _Newptr, _Newptr + 1);
                }
            else
                {   // not first growth, adjust pointers
                _Seekhigh = _Newptr + (_Seekhigh - _Oldptr);
                _Mysb::setp(_Newptr + (_Mysb::pbase() - _Oldptr),
                    _Newptr + (_Mysb::pptr() - _Oldptr),
                    _Newptr + _Newsize);
                if (_Mystate & _Noread)
                    _Mysb::setg(_Newptr, 0, _Newptr);
                else
                    _Mysb::setg(_Newptr,
                        _Newptr + (_Mysb::gptr() - _Oldptr),
                        _Mysb::pptr() + 1);
                }
 
            if (_Mystate & _Allocated)
                _Al.deallocate(_Oldptr, _Oldsize);
            _Mystate |= _Allocated;
 
            *_Mysb::_Pninc() = _Traits::to_char_type(_Meta);
            return (_Meta);
            }
        }
 
    virtual int_type __CLR_OR_THIS_CALL pbackfail(int_type _Meta = _Traits::eof())
        {   // put an element back to stream
        if (_Mysb::gptr() == 0
            || _Mysb::gptr() <= _Mysb::eback()
            || !_Traits::eq_int_type(_Traits::eof(), _Meta)
            && !_Traits::eq(_Traits::to_char_type(_Meta), _Mysb::gptr()[-1])
            && _Mystate & _Constant)
            return (_Traits::eof());    // can't put back, fail
        else
            {   // back up one position and store put-back character
            _Mysb::gbump(-1);
            if (!_Traits::eq_int_type(_Traits::eof(), _Meta))
                *_Mysb::gptr() = _Traits::to_char_type(_Meta);
            return (_Traits::not_eof(_Meta));
            }
        }
 
    virtual int_type __CLR_OR_THIS_CALL underflow()
        {   // get an element from stream, but don't point past it
        if (_Mysb::gptr() == 0)
            return (_Traits::eof());    // no character buffer, fail
        else if (_Mysb::gptr() < _Mysb::egptr())
            return (_Traits::to_int_type(*_Mysb::gptr()));  // return buffered
        else if (_Mystate & _Noread || _Mysb::pptr() == 0
            || _Mysb::pptr() <= _Mysb::gptr() && _Seekhigh <= _Mysb::gptr())
            return (_Traits::eof());    // can't read, fail
        else
            {   // extend read buffer into written area, then return buffered
            if (_Seekhigh < _Mysb::pptr())
                _Seekhigh = _Mysb::pptr();
            _Mysb::setg(_Mysb::eback(), _Mysb::gptr(), _Seekhigh);
            return (_Traits::to_int_type(*_Mysb::gptr()));
            }
        }
 
    virtual pos_type __CLR_OR_THIS_CALL seekoff(off_type _Off,
        ios_base::seekdir _Way,
        ios_base::openmode _Which = ios_base::in | ios_base::out)
        {   // change position by _Off, according to _Way, _Mode
        if (_Mysb::pptr() != 0 && _Seekhigh < _Mysb::pptr())
            _Seekhigh = _Mysb::pptr();  // update high-water pointer
 
        if (_Which & ios_base::in && _Mysb::gptr() != 0)
            {   // position within read buffer
            if (_Way == ios_base::end)
                _Off += (off_type)(_Seekhigh - _Mysb::eback());
            else if (_Way == ios_base::cur
                && (_Which & ios_base::out) == 0)
                _Off += (off_type)(_Mysb::gptr() - _Mysb::eback());
            else if (_Way != ios_base::beg)
                _Off = _BADOFF;
 
            if (0 <= _Off && _Off <= _Seekhigh - _Mysb::eback())
                {   // change read position
                _Mysb::gbump((int)(_Mysb::eback() - _Mysb::gptr() + _Off));
                if (_Which & ios_base::out && _Mysb::pptr() != 0)
                    _Mysb::setp(_Mysb::pbase(), _Mysb::gptr(),
                        _Mysb::epptr());    // change write position to match
                }
            else
                _Off = _BADOFF;
            }
        else if (_Which & ios_base::out && _Mysb::pptr() != 0)
            {   // position within write buffer
            if (_Way == ios_base::end)
                _Off += (off_type)(_Seekhigh - _Mysb::eback());
            else if (_Way == ios_base::cur)
                _Off += (off_type)(_Mysb::pptr() - _Mysb::eback());
            else if (_Way != ios_base::beg)
                _Off = _BADOFF;
 
            if (0 <= _Off && _Off <= _Seekhigh - _Mysb::eback())
                _Mysb::pbump((int)(_Mysb::eback()
                    - _Mysb::pptr() + _Off));   // change write position
            else
                _Off = _BADOFF;
            }
        else
            _Off = _BADOFF; // neither read nor write buffer selected, fail
        return (pos_type(_Off));
        }
 
    virtual pos_type __CLR_OR_THIS_CALL seekpos(pos_type _Ptr,
        ios_base::openmode _Mode = ios_base::in | ios_base::out)
        {   // change position to _Pos, according to _Mode
        streamoff _Off = (streamoff)_Ptr;
        if (_Mysb::pptr() != 0 && _Seekhigh < _Mysb::pptr())
            _Seekhigh = _Mysb::pptr();  // update high-water pointer
 
        if (_Off == _BADOFF)
            ;
        else if (_Mode & ios_base::in && _Mysb::gptr() != 0)
            {   // position within read buffer
            if (0 <= _Off && _Off <= _Seekhigh - _Mysb::eback())
                {   // change read position
                _Mysb::gbump((int)(_Mysb::eback() - _Mysb::gptr() + _Off));
                if (_Mode & ios_base::out && _Mysb::pptr() != 0)
                    _Mysb::setp(_Mysb::pbase(), _Mysb::gptr(),
                        _Mysb::epptr());    // change write position to match
                }
            else
                _Off = _BADOFF;
            }
        else if (_Mode & ios_base::out && _Mysb::pptr() != 0)
            {   // position within write buffer
            if (0 <= _Off && _Off <= _Seekhigh - _Mysb::eback())
                _Mysb::pbump((int)(_Mysb::eback()
                    - _Mysb::pptr() + _Off));   // change write position
            else
                _Off = _BADOFF;
            }
        else
            _Off = _BADOFF;
        return (streampos(_Off));
        }
 
    void __CLR_OR_THIS_CALL _Init(const _Elem *_Ptr,
        size_t _Count, _Strstate _State)
        {   // initialize buffer to [_Ptr, _Ptr + _Count), set state
        _Seekhigh = 0;
        _Mystate = _State;
 
        if (_Count != 0
            && (_Mystate & (_Noread | _Constant)) != (_Noread | _Constant))
            {   // finite buffer that can be read or written, set it up
            _Elem *_Pnew = _Al.allocate(_Count);
            _Traits_helper::copy_s<_Traits>(_Pnew, _Count, _Ptr, _Count);
            _Seekhigh = _Pnew + _Count;
 
            if (!(_Mystate & _Noread))
                _Mysb::setg(_Pnew, _Pnew,
                    _Pnew + _Count);    // setup read buffer
            if (!(_Mystate & _Constant))
                {   // setup write buffer, and maybe read buffer
                _Mysb::setp(_Pnew,
                    (_Mystate & _Atend) ? _Pnew + _Count : _Pnew,
                    _Pnew + _Count);
                if (_Mysb::gptr() == 0)
                    _Mysb::setg(_Pnew, 0, _Pnew);
                }
            _Mystate |= _Allocated;
            }
        }
 
    void __CLR_OR_THIS_CALL _Tidy()
        {   // discard any allocated buffer and clear pointers
        if (_Mystate & _Allocated)
            _Al.deallocate(_Mysb::eback(),
                (_Mysb::pptr() != 0 ? _Mysb::epptr()
                    : _Mysb::egptr()) - _Mysb::eback());
        _Mysb::setg(0, 0, 0);
        _Mysb::setp(0, 0);
        _Seekhigh = 0;
        _Mystate &= ~_Allocated;
        }
 
private:
    enum
        {   // constant for minimum buffer size
        _MINSIZE = 32};
 
    _Strstate __CLR_OR_THIS_CALL _Getstate(ios_base::openmode _Mode)
        {   // convert open mode to stream state bits
        _Strstate _State = (_Strstate)0;
        if (!(_Mode & ios_base::in))
            _State |= _Noread;
        if (!(_Mode & ios_base::out))
            _State |= _Constant;
        if (_Mode & ios_base::app)
            _State |= _Append;
        if (_Mode & ios_base::ate)
            _State |= _Atend;
        return (_State);
        }
 
    _Elem *_Seekhigh;   // the high-water pointer in character array
    _Strstate _Mystate; // the stream state
    allocator_type _Al; // the allocator object
    };
 
 #if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
 
template class _CRTIMP2_PURE basic_stringbuf<char,
    char_traits<char>, allocator<char> >;
template class _CRTIMP2_PURE basic_stringbuf<wchar_t,
    char_traits<wchar_t>, allocator<wchar_t> >;
 
 
 
 #endif /* _DLL_CPPLIB */
 
        // TEMPLATE CLASS basic_istringstream
template<class _Elem,
    class _Traits,
    class _Alloc>
    class basic_istringstream
        : public basic_istream<_Elem, _Traits>
    {   // input stream associated with a character array
public:
    typedef _Alloc allocator_type;
    typedef basic_stringbuf<_Elem, _Traits, _Alloc> _Mysb;
    typedef basic_string<_Elem, _Traits, _Alloc> _Mystr;
 
    explicit __CLR_OR_THIS_CALL basic_istringstream(ios_base::openmode _Mode = ios_base::in)
        : basic_istream<_Elem, _Traits>(&_Stringbuffer),
            _Stringbuffer(_Mode | ios_base::in)
        {   // construct empty readable character buffer
        }
 
    explicit __CLR_OR_THIS_CALL basic_istringstream(const _Mystr& _Str,
        ios_base::openmode _Mode = ios_base::in)
        : basic_istream<_Elem, _Traits>(&_Stringbuffer),
            _Stringbuffer(_Str, _Mode | ios_base::in)
        {   // construct readable character buffer from NTCS
        }
 
    virtual __CLR_OR_THIS_CALL ~basic_istringstream()
        {   // destroy the object
        }
 
    _Mysb *__CLR_OR_THIS_CALL rdbuf() const
        {   // return pointer to file buffer
        return ((_Mysb *)&_Stringbuffer);
        }
 
    _Mystr __CLR_OR_THIS_CALL str() const
        {   // return string copy of character array
        return (_Stringbuffer.str());
        }
 
    void __CLR_OR_THIS_CALL str(const _Mystr& _Newstr)
        {   // replace character array from string
        _Stringbuffer.str(_Newstr);
        }
 
private:
    _Mysb _Stringbuffer;    // the string buffer
    };
 
 #if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
 
template class _CRTIMP2_PURE basic_istringstream<char,
    char_traits<char>, allocator<char> >;
template class _CRTIMP2_PURE basic_istringstream<wchar_t,
    char_traits<wchar_t>, allocator<wchar_t> >;
 
 
 
 #endif /* _DLL_CPPLIB */
 
        // TEMPLATE CLASS basic_ostringstream
template<class _Elem,
    class _Traits,
    class _Alloc>
    class basic_ostringstream
        : public basic_ostream<_Elem, _Traits>
    {   // output stream associated with a character array
public:
    typedef _Alloc allocator_type;
    typedef basic_stringbuf<_Elem, _Traits, _Alloc> _Mysb;
    typedef basic_string<_Elem, _Traits, _Alloc> _Mystr;
 
    explicit __CLR_OR_THIS_CALL basic_ostringstream(ios_base::openmode _Mode = ios_base::out)
        : basic_ostream<_Elem, _Traits>(&_Stringbuffer),
            _Stringbuffer(_Mode | ios_base::out)
        {   // construct empty writable character buffer
        }
 
    explicit __CLR_OR_THIS_CALL basic_ostringstream(const _Mystr& _Str,
        ios_base::openmode _Mode = ios_base::out)
        : basic_ostream<_Elem, _Traits>(&_Stringbuffer),
            _Stringbuffer(_Str, _Mode | ios_base::out)
        {   // construct writable character buffer from NTCS
        }
 
    virtual __CLR_OR_THIS_CALL ~basic_ostringstream()
        {   // destroy the object
        }
 
    _Mysb *__CLR_OR_THIS_CALL rdbuf() const
        {   // return pointer to buffer
        return ((_Mysb *)&_Stringbuffer);
        }
 
    _Mystr __CLR_OR_THIS_CALL str() const
        {   // return string copy of character array
        return (_Stringbuffer.str());
        }
 
    void __CLR_OR_THIS_CALL str(const _Mystr& _Newstr)
        {   // replace character array from string
        _Stringbuffer.str(_Newstr);
        }
 
private:
    _Mysb _Stringbuffer;    // the string buffer
    };
 
 #if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
 
template class _CRTIMP2_PURE basic_ostringstream<char,
    char_traits<char>, allocator<char> >;
template class _CRTIMP2_PURE basic_ostringstream<wchar_t,
    char_traits<wchar_t>, allocator<wchar_t> >;
 
 
 
 #endif /* _DLL_CPPLIB */
 
        // TEMPLATE CLASS basic_stringstream
template<class _Elem,
    class _Traits,
    class _Alloc>
    class basic_stringstream
        : public basic_iostream<_Elem, _Traits>
    {   // input/output stream associated with a character array
public:
    typedef _Elem char_type;
    typedef _Traits traits_type;
    typedef _Alloc allocator_type;
    typedef typename _Traits::int_type int_type;
    typedef typename _Traits::pos_type pos_type;
    typedef typename _Traits::off_type off_type;
    typedef basic_string<_Elem, _Traits, _Alloc> _Mystr;
 
    explicit __CLR_OR_THIS_CALL basic_stringstream(ios_base::openmode _Mode =
        ios_base::in | ios_base::out)
        : basic_iostream<_Elem, _Traits>(&_Stringbuffer),
            _Stringbuffer(_Mode)
        {   // construct empty character buffer
        }
 
    explicit __CLR_OR_THIS_CALL basic_stringstream(const _Mystr& _Str,
        ios_base::openmode _Mode = ios_base::in | ios_base::out)
        : basic_iostream<_Elem, _Traits>(&_Stringbuffer),
            _Stringbuffer(_Str, _Mode)
        {   // construct character buffer from NTCS
        }
 
    virtual __CLR_OR_THIS_CALL ~basic_stringstream()
        {   // destroy the object
        }
 
    basic_stringbuf<_Elem, _Traits, _Alloc> *__CLR_OR_THIS_CALL rdbuf() const
        {   // return pointer to buffer
        return ((basic_stringbuf<_Elem, _Traits, _Alloc> *)&_Stringbuffer);
        }
 
    _Mystr __CLR_OR_THIS_CALL str() const
        {   // return string copy of character array
        return (_Stringbuffer.str());
        }
 
    void __CLR_OR_THIS_CALL str(const _Mystr& _Newstr)
        {   // replace character array from string
        _Stringbuffer.str(_Newstr);
        }
 
private:
    basic_stringbuf<_Elem, _Traits, _Alloc>
        _Stringbuffer;  // the string buffer
    };
 
 #if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
 
template class _CRTIMP2_PURE basic_stringstream<char,
    char_traits<char>, allocator<char> >;
template class _CRTIMP2_PURE basic_stringstream<wchar_t,
    char_traits<wchar_t>, allocator<wchar_t> >;
 
 
 
 #endif /* _DLL_CPPLIB */
_STD_END
 
#ifdef _MSC_VER
 #pragma warning(pop)
 #pragma pack(pop)
#endif  /* _MSC_VER */
 
#endif /* RC_INVOKED */
#endif /* _SSTREAM_ */
  • Home
  • Forum
  • Qt
  • Qt Programming
  • Howto use Qt with Boost ?

  1. 1st October 2009, 13:50


    #1

    Default Howto use Qt with Boost ?

    Hello all,

    I am using Qt on Windows with MinGW. I added boost library by using INCLUDEPATH in the .pro file and compiled the sample program from boost’s Getting Started on Windows.

    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;

    std::for_each(
    in(std::cin), in(), std::cout << (_1 * 3) << » » );

    Now I receive the errors:
    error: `cin’ is not a member of `std’
    error: `cout’ is not a member of `std’

    Do namespaces std and boost interfere?
    Can I find a tutorial howto use Qt with Boost somewhere?


  2. 1st October 2009, 14:19


    #2

    Default Re: Howto use Qt with Boost ?

    There is no problem using std neither boost with Qt. Just a question of includes and link.

    In your sample, be sure to include <iostream> and <algorithm>


  3. The following user says thank you to scascio for this useful post:

    bilgenratte (1st October 2009)


  4. 1st October 2009, 14:40


    #3


  5. 1st October 2009, 15:12


    #4

    Default Re: Howto use Qt with Boost ?

    unless you want to use Boost.Signals, then you need to specify in your .pro file

    1. CONFIG += no_keywords // for Boost.Signals

    To copy to clipboard, switch view to plain text mode 

    and use Q_SIGNALS, S_SLOTS, Q_EMIT etc instead of signals, slots, emit…

    HTH


Similar Threads

  1. Replies: 0

    Last Post: 25th June 2009, 09:17

  2. Replies: 2

    Last Post: 1st April 2009, 08:37

  3. Replies: 3

    Last Post: 12th June 2008, 15:53

  4. Replies: 3

    Last Post: 3rd May 2007, 11:48

  5. Replies: 3

    Last Post: 28th January 2007, 21:21

Bookmarks

Bookmarks


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
  • BB code is On
  • Smilies are On
  • [IMG] code is On
  • [VIDEO] code is On
  • HTML code is Off

Forum Rules

Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Error checking type of the expression
  • Error checking tls connection host is not running
  • Error checking tls connection docker
  • Error checking storage configuration
  • Error checking mode

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии