[英]Visual studio Error C2784
我在Linux上使用g ++編譯器的簡單代碼有問題,但在Windows上使用Visual Studio Professional 2012卻遇到很多錯誤。
編碼:
string tmp = *path;
if(tmp.length() == 0)
*path = Name_;
else
*path = Name_ + '.' + tmp;
錯誤:
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'
該程序將我指向+運算符。 我的內容還包括:
#include <iostream>
#include <stdio.h>
#include <string.h>
另外,我對cout <<也有疑問。 盡管包含iostream,但Visual Studio無法識別運算符<<。
謝謝
您需要#include <string>
而不是string.h
(后者聲明C字符串函數,例如strstr
, strcmp
等)。
如果您的操作數是std::string
,則包括<string>
可能還會解決<<
不能識別的問題。
編輯: if (tmp.empty())
, if (tmp.empty())
通常比if(tmp.length() == 0)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.