PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code. Along with the proper indenting and line spacing it makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/ http://www.cplusplus.com/articles/z13hAqkS/ Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you. You can use the preview button at the bottom to see how it looks. *** I found the second link to be the most help. *** Revised 08/16/2021 |
std::string ss;
and not have the compiler complain, but when you get to out << ss;
"cout" or "out" do not know how to process the string with out the header file.ofstream out("/Users/rmcinnes/Downloads/OutFile.txt");
, but how do you know if it is open and ready to use? Just because an "ofstream" will create the file if needed does not mean that it will. You could have a problem with the path that keeps the file from opening or being created.rjmcinnes wrote: |
---|
The code works just fine as a test code in another program... But not an add in to my main application... That is what has me puzzled. |
|
|
|
|
|
|
|
|
|
|
In file included from test.cpp:4: iprecision.h: In constructor 'int_precision::int_precision(const char*)': iprecision.h:374:8: error: 'strlen' was not declared in this scope if( strlen(str) == 0 ) ^~~~~~ iprecision.h:374:8: note: 'strlen' is defined in header '<cstring>'; did you forget to '#include <cstring>'? iprecision.h:122:1: +#include <cstring> using std::atoi; using std::strtoul; iprecision.h:374:8: if( strlen(str) == 0 ) ^~~~~~ test.cpp: In function 'int main()': test.cpp:11:9: error: ambiguous overload for 'operator<<' (operand types are 'std::ofstream' {aka 'std::basic_ofstream<char>'} and 'std::__cxx11::string' {aka 'std::__cxx11::basic_string<char>'}) fout << ss; ~~~~~^~~~~ In file included from test.cpp:4: iprecision.h:1865:43: note: candidate: 'int_precision operator<<(const _Ty&, const int_precision&) [with _Ty = std::basic_ofstream<char>]' template <class _Ty> inline int_precision operator<<( const _Ty& lhs, const int_precision& rhs ) ^~~~~~~~ In file included from C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/string:52, from C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/locale_classes.h:40, from C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/ios_base.h:41, from C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:42, from C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38, from C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39, from test.cpp:1: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/basic_string.h:6284:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]' operator<<(basic_ostream<_CharT, _Traits>& __os, ^~~~~~~~ In file included from test.cpp:4: iprecision.h: At global scope: iprecision.h:107:13: warning: '_VI_' defined but not used [-Wunused-variable] static char _VI_[] = "@(#)iprecision.h 02.08 -- Copyright (C) Henrik Vestermark"; |
|
|
In function 'int main()': 24:9: error: ambiguous overload for 'operator<<' (operand types are 'std::ofstream {aka std::basic_ofstream<char>}' and 'std::string {aka std::basic_string<char>}') 24:9: note: candidates are: 13:36: note: int_precision operator<<(const _Ty&, const int_precision&) [with _Ty = std::basic_ofstream<char>] In file included from /usr/include/c++/4.9/string:52:0, from /usr/include/c++/4.9/bits/locale_classes.h:40, from /usr/include/c++/4.9/bits/ios_base.h:41, from /usr/include/c++/4.9/ios:42, from /usr/include/c++/4.9/ostream:38, from /usr/include/c++/4.9/iostream:39, from 1: /usr/include/c++/4.9/bits/basic_string.h:2772:5: note: std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] operator<<(basic_ostream<_CharT, _Traits>& __os, ^ |