Guest User

Untitled

a guest
Aug 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. getting information from standard output ( C )?
  2. string s;
  3. fstream fs("/dev/stdout", fstream::in);
  4. fs >> s;
  5.  
  6. cat file_with_nulls
  7.  
  8. cat file_with_nulls > otherfile
  9.  
  10. ./myprog > output.bin
  11.  
  12. char cstr[] = { 'H', 'e', 0, 'l', 'l', 'o', 0 };
  13.  
  14. std::string s1(cstr); // wrong, gives you "He"
  15. std::string s2(cstr, sizeof(cstr)); // correct
  16.  
  17. std::string result;
  18. std::fstream fs( "/dev/stdout", std::fstream::in|std::fstream::binary );
  19. while ( !fs.eof() ) {
  20. std::string b;
  21. fs >> b;
  22. result += b;
  23. }
  24. fs.close();
  25.  
  26. std::fstream out( "C:\tmp\test1.txt", std::fstream::out );
  27. out.write( "aaanbbbccc", 13 );
  28. out.close();
Add Comment
Please, Sign In to add comment