만약에 long double 형의 a 변수에 999999999999999999999999999999999999값이 들어가 있다고 했을 때 이값을 문자열 형태로 변환 시켜서 char or string형 변수에 집어넣어야 하는데...감이 잘안잡힙니다.
간단하게...
sprintf(str_buf, "%f", a)
로 하는게 ....
from saibi
C++라면 stringstream을 쓰세요.
다음은 Boost 라이브러리의 lexical_cast 함수 정의입니다(일부 수정).
template<typename Target, typename Source> Target lexical_cast(Source arg) { std::stringstream interpreter; Target result; if(!(interpreter << arg && interpreter >> result)) throw_exception(bad_lexical_cast(typeid(Target), typeid(Source))); return result; }
사용법은 다른 형변환 연산자 사용하듯이 하면 됩니다.
int main(int argc, char * argv[]) { using boost::lexical_cast; using boost::bad_lexical_cast; std::vector<long double> args; while(*++argv) { try { args.push_back(lexical_cast<long double>(*argv)); } catch(bad_lexical_cast &) { args.push_back(0); } } ... }
#include<algorithm> #include<string> long double int whatever = 999~~~~~; string answer; while( whatever) { answer.append( whatever %10 + '0'); whatever /=10; } reverse(answer.begin(),answer.end() );
C++, 그리고 C++.... 죽어도 C++
%f 연산자로 하니까..warnning 떨어집니다. long double 형 포맷 스트링 연산자는 어케되는지요?
http://www.cplusplus.com/ref/cstdio/sprintf.html
여기를 참고하세용 모디파이어를 L을 써주면 됩니다.
모디파이어를 L을 써주면 됩니다
%Lf 입니다.
텍스트 포맷에 대한 자세한 정보
<code>
<blockcode>
<apache>
<applescript>
<autoconf>
<awk>
<bash>
<c>
<cpp>
<css>
<diff>
<drupal5>
<drupal6>
<gdb>
<html>
<html5>
<java>
<javascript>
<ldif>
<lua>
<make>
<mysql>
<perl>
<perl6>
<php>
<pgsql>
<proftpd>
<python>
<reg>
<spec>
<ruby>
<foo>
[foo]
간단하게...sprintf(str_buf, "%f", a)
간단하게...
sprintf(str_buf, "%f", a)
로 하는게 ....
from saibi
C라면 sprintf를...
C++라면 stringstream을 쓰세요.
다음은 Boost 라이브러리의 lexical_cast 함수 정의입니다(일부 수정).
사용법은 다른 형변환 연산자 사용하듯이 하면 됩니다.
[code:1]#include<algorithm>#in
한번해봤습니다
동작하는지는 잘 -_-;;
해보고 싶었서요 ㅠ.ㅜ
C++, 그리고 C++....
죽어도 C++
[quote]sprintf(str_buf, "%f", a) [/quote
%f 연산자로 하니까..warnning 떨어집니다.
long double 형 포맷 스트링 연산자는 어케되는지요?
http://www.cplusplus.com/ref/cstdio/spri
http://www.cplusplus.com/ref/cstdio/sprintf.html
여기를 참고하세용 모디파이어를 L을 써주면 됩니다.
C++, 그리고 C++....
죽어도 C++
[quote]모디파이어를 L을 써주면 됩니다[/quote]%L 이렇게
%L 이렇게 쓰라는 말씀이신가요?
이렇게 써도 마찬가지인데~~~!!
%Lf 입니다.
%Lf 입니다.
from saibi
댓글 달기