Skip to content

Instantly share code, notes, and snippets.

@artemp
Created May 10, 2013 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artemp/45d5d82ed5696978e7c4 to your computer and use it in GitHub Desktop.
Save artemp/45d5d82ed5696978e7c4 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <sstream>
int main(int argc,char** argv)
{
std::ostringstream out;
char * str = "ABCD-";
out.write(str,5);
out.write(str,5);
out.write(str,5);
std::cerr << out.tellp() << std::endl;
std::cerr << "seek 5" << std::endl;
out.seekp(5, std::ios::beg);
std::cerr << out.fail() << " " << out.good() << " " << out.eof() << std::endl ;
std::cerr << out.tellp() << std::endl;
std::cerr << "seek 15" << std::endl;
out.seekp(15,std::ios::beg);
std::cerr << out.fail() << " " << out.good() << " " << out.eof() << std::endl ;
std::cerr << out.tellp() << std::endl;
std::cerr << "seek 25" << std::endl;
out.seekp(25, std::ios::beg);
std::cerr << out.fail() << " " << out.good() << " " << out.eof() << std::endl ;
std::cerr << out.tellp() << std::endl;
std::cerr << "seek 10" << std::endl;
out.seekp(10, std::ios::beg);
std::cerr << out.fail() << " " << out.good() << " " << out.eof() << std::endl ;
std::cerr << out.tellp() << std::endl;
std::cerr << out.str() << std::endl;
return EXIT_SUCCESS;
}
@springmeyer
Copy link

I get with clang++ / libstdc++:

~/projects/mapnik8[master]$ clang++ -o seek seek.cpp 
seek.cpp:8:18: warning: conversion from string literal to 'char *' is deprecated [-Wdeprecated-writable-strings]
    char * str = "ABCD-";
                 ^
1 warning generated.
~/projects/mapnik8[master]$ ./seek 
15
seek 5
0 1 0
5
seek 15
0 1 0
15
seek 25
1 0 0
-1
seek 10
1 0 0
-1
ABCD-ABCD-ABCD-

@artemp
Copy link
Author

artemp commented May 10, 2013

15
seek 5
0 1 0
5
seek 15
0 1 0
15
seek 25
0 1 0
15
seek 10
0 1 0
10
ABCD-ABCD-ABCD-

@springmeyer
Copy link

~/projects/mapnik8[master]$ clang++ -o seek seek.cpp -L/usr/lib -stdlib=libc++
seek.cpp:8:18: warning: conversion from string literal to 'char *' is deprecated [-Wdeprecated-writable-strings]
    char * str = "ABCD-";
                 ^
1 warning generated.
~/projects/mapnik8[master]$ otool -L seek
seek:
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 65.1.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
~/projects/mapnik8[master]$ ./seek 
15
seek 5
0 1 0
5
seek 15
0 1 0
15
seek 25
0 1 0
15
seek 10
0 1 0
10
ABCD-ABCD-ABCD-

@artemp
Copy link
Author

artemp commented May 10, 2013

clang version 3.3 (179091)
Target: x86_64-apple-darwin12.3.0
Thread model: posix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment