[英]c++ Fstream string combination error
我試圖做一個寫.ps1腳本的函數。 我正在學習fstream函數和方法,遇到了一些麻煩。 我找不到讓Fstream在給定路徑(path1)上創建文件並同時為文件和擴展名添加給定名稱的方法。
void write(string s, string name) {
ostringstream fille;
fille << "$client = new-object System.Net.WebClient\n" << s;
string fil = fille.str();
ostringstream pat;
pat << path1 << "/" << ".ps1";
string path = pat.str();
fstream file(path);
if (file.open()) {
file << fil;
file.close();
}
}
在編譯期間,我收到以下錯誤消息(在if
行上):
沒有重載函數實例“
std::basic_fstream<_Elem, _Traits>::open
[with _Elem =char
,_Traits =std::char_traits<char>
]”與參數列表匹配C2661'std
std::basic_fstream<char,std::char_traits<char>>::open
':沒有重載函數接受0個參數
首先,您不使用name
參數。 其次,您不定義path1變量。 如果您使用fstream的初始化構造函數,則無需調用fstream::open
方法。
void write( const std::string & s, const std::string & name )
{
std::string fil("$client = new-object System.Net.WebClient\n");
fil += s;
std::ostringstream path;
path << "C:/Folder/" << name << ".ps1";
std::ofstream file( path.str() );
if ( file.is_open() ) {
file << fil;
file.close();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.