I have this code:
char shaderName[128] = "";//the name of the file
char text[1024 * 16] = "";//the content of the file
std::ofstream myfile;//the file
myfile.open(shaderName + ".shader");//i want to concatenate the file name with the .shader extension
myfile << text;//put the content of the text array in the file
myfile.close();//close the file
This gives me an error. It tells me i can't convert a char array to a string or const char*. I want to be able to concatenate the nameof the file with the .shader
extension. I also tried to cast shaderName
to an (std::string)
or a const char*
EDIT:
ImGui::Begin("Shader Writer");
char text[1024 * 16] = {""};
char shaderName[128] = {""};
ImGui::InputTextMultiline("##source", text, IM_ARRAYSIZE(text), ImVec2(-1.0f, ImGui::GetWindowHeight()), ImGuiInputTextFlags_AllowTabInput | (false ? ImGuiInputTextFlags_ReadOnly : 0));
ImGui::Text("Shader Name: ");
ImGui::InputText("", shaderName, IM_ARRAYSIZE(shaderName));
ImGui::SameLine(0.0f, 2.0f);
if(ImGui::Button("Create", ImVec2(50, 20)))
{
char shaderName[128] = "";
std::ofstream myfile;
std::string name(shaderName);
std::string FileName = name + ".shader";
myfile.open(FileName.c_str());
myfile << text;
myfile.close();
}
ImGui::End();
The InputTextMultiline() function let's you modify,write,read a text. The "text" in this case is a char array(this function outputs a char array). Then we have another InputTextMultiline() function which also returns a char array. In order to use this data returned by these functions, i need to convert them to strings(or maybe to const char*,even tho i think std::strings is better).
Here is a rapresentation of what these functions do: