Reputation: 57
I have a problem with simple code that working with g++ compiler on Linux but I got many Errors with Visual studio professional 2012 on Windows.
The code:
string tmp = *path;
if(tmp.length() == 0)
*path = Name_;
else
*path = Name_ + '.' + tmp;
The Error:
Error 1 error C2784: 'std::_String_iterator<_Mystr> std::operator +(_String_iterator<_Mystr>::difference_type,std::_String_iterator<_Mystr>)' : could not deduce template argument for 'std::_String_iterator<_Mystr>' from 'char'
The program points me to + operator. Also my includes are:
#include <iostream>
#include <stdio.h>
#include <string.h>
In addition I have a problems with cout <<. The operator << does not recognized by Visual studio although iostream included.
Thanks
Upvotes: 2
Views: 6686
Reputation: 490728
You need to #include <string>
instead of string.h
(the latter declares C string functions like strstr
, strcmp
, etc.)
If your operand is a std::string
, including <string>
will probably also fix the problem with <<
not being recognized.
Edit: as an aside, if (tmp.empty())
is generally preferred over if(tmp.length() == 0)
.
Upvotes: 3