簡體   English   中英

字符串后的名稱* .bin文件

[英]Name *.bin file after string

我試圖通過stdin從用戶那里獲取一個字符串,並將其保存到變量InputString ,然后創建一個與InputString的值同名的二進制文件。 這是我到目前為止編寫的代碼:

std::string InputString;
getline(std::cin, InputString);

std::cout << InputString << std::endl;

// The code above works.
// Errors start below. :(

void Printi(std::string filename)
{
    std::ofstream Printi(filename".bin");
    Printi((char*)&Hans, sizeof(Person));  // Hans is an instance of my class Person.
    Printi.close();
}

Printi(InputString);

我收到以下錯誤(從本地化的編譯器翻譯成英文):

"Printi": Local function definition is not allowed 

Missing ")" (in line std::ofstream Printi..) 

如何僅使用標准C ++庫解決此問題?

std::ofstream Printi(filename".bin")需要為std::ofstream Printi(filename + ".bin") +運算符用於連接字符串,並將.bin附加到文件名中所提供內容的末尾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM