由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - c++ template中如何判断类型
相关主题
一个简单的算法问题?IDL一问
c的问题(2)请看看这个Perl random sampling code 有什么问题,
请问这是什么错误呀c++ 中如何把str转换为float?
C的问题,困惑中[合集] ofstream 无法使用binary mode的问题
a C++ interview question..........大家帮我看看C文件输入函数fprintf的问题
ofstream and cout question在帮忙看看这个吧 C: int->char*
ostream& operator << (ostream& s, int cnt) error这个怎么allocate memory?
C++ problem请高人解释一下为啥这个输出总是"HELLO-ERR"
相关话题的讨论汇总
话题: datat话题: 类型话题: fprintf话题: template话题: file
进入Programming版参与讨论
1 (共1页)
l*****e
发帖数: 64
1
在c++ template编程中如何判断数据的类型?
比如下面的代码,我需要确定DataT的类型,比如int, float等,
然后根据类型相应修改fprintf的参数输出。
谢了先。
template
void
myArray::write( File &file )
{
for ( unsigned i=Array::_base; !file.error()&&(i<_mysize); i++ )
{
fprintf (file, "%d %g\n", i, float (Array::_data[i]) );
}
}
f*******y
发帖数: 988
2
写specialization

【在 l*****e 的大作中提到】
: 在c++ template编程中如何判断数据的类型?
: 比如下面的代码,我需要确定DataT的类型,比如int, float等,
: 然后根据类型相应修改fprintf的参数输出。
: 谢了先。
: template
: void
: myArray::write( File &file )
: {
: for ( unsigned i=Array::_base; !file.error()&&(i<_mysize); i++ )
: {

d*******d
发帖数: 2050
3
用ofstream不就行了,不用你自己去判断类型。

【在 l*****e 的大作中提到】
: 在c++ template编程中如何判断数据的类型?
: 比如下面的代码,我需要确定DataT的类型,比如int, float等,
: 然后根据类型相应修改fprintf的参数输出。
: 谢了先。
: template
: void
: myArray::write( File &file )
: {
: for ( unsigned i=Array::_base; !file.error()&&(i<_mysize); i++ )
: {

l*****e
发帖数: 64
4
能说得稍微详细点吗?

【在 f*******y 的大作中提到】
: 写specialization
l*****e
发帖数: 64
5
是个好建议。
不过就是为了统一风格,程序中没有用到ofstream等作为文件输出。

【在 d*******d 的大作中提到】
: 用ofstream不就行了,不用你自己去判断类型。
h**o
发帖数: 347
6
why mix c & c++...

【在 l*****e 的大作中提到】
: 在c++ template编程中如何判断数据的类型?
: 比如下面的代码,我需要确定DataT的类型,比如int, float等,
: 然后根据类型相应修改fprintf的参数输出。
: 谢了先。
: template
: void
: myArray::write( File &file )
: {
: for ( unsigned i=Array::_base; !file.error()&&(i<_mysize); i++ )
: {

l*****e
发帖数: 64
7
good point, hehe
but i don't know either, since this is from a large toolkit on which my
codes based

【在 h**o 的大作中提到】
: why mix c & c++...
l*****e
发帖数: 64
8
i guess one reason maybe that:
it's more flexible to control the reading/writing using fprintf/sscanf than
ofstream, especially when working with a bit complex data.

【在 h**o 的大作中提到】
: why mix c & c++...
t****t
发帖数: 6806
9
真的要用printf的话,你可以先用ostringstream得到string,再用printf输出
不混合printf和ostream倒是对的.
虽然我觉得这样的代码非常傻

than

【在 l*****e 的大作中提到】
: i guess one reason maybe that:
: it's more flexible to control the reading/writing using fprintf/sscanf than
: ofstream, especially when working with a bit complex data.

s*******d
发帖数: 59
10
C++吸收新东西和发展的速度太慢了,感觉现在做应用不如java,.net, 做系统
不如C。
1 (共1页)
进入Programming版参与讨论
相关主题
请高人解释一下为啥这个输出总是"HELLO-ERR"a C++ interview question..........
为什么在overloading中,friend <<不能读取private值呢?ofstream and cout question
c++ template question:ostream& operator << (ostream& s, int cnt) error
C++ template questionC++ problem
一个简单的算法问题?IDL一问
c的问题(2)请看看这个Perl random sampling code 有什么问题,
请问这是什么错误呀c++ 中如何把str转换为float?
C的问题,困惑中[合集] ofstream 无法使用binary mode的问题
相关话题的讨论汇总
话题: datat话题: 类型话题: fprintf话题: template话题: file