invalid conversion from ‘const char*’ to ‘char’

2013年2月19日 03:24

In C++, the token " " is a string literal which represents an array of two characters: the value of a space in the character set (eg, the value 32 in ascii) and a zero. On the other hand, the token ' ' represents a single character with the value of a space (usually 32). Note that in C, the token ' ' represents an integer with the value of a space. (In C, sizeof( ' ' ) == sizeof( int ), while in C++, sizeof( ' ' ) == 1.)

so getline(cNum, 255, " ") should be getline(cNum, 255, ' ') to get every word in one line

 char cNum[255];
 in_file.getline(cNum, 255, ' ');
 data = atof(cNum); //atof returns to double
 cout<<data<<" ";

评论(0) 阅读(2104)

C++ —用sstream把int转成string类型的方法

2011年9月15日 08:59


In order to convert an int (or any other numeric type, e.g., float, double, etc.) to string, you can use:

#include <sstream>

int i = 5;
std::string s;
std::stringstream out;
out << i;
s = out.str();


评论(2) 阅读(2347)