I'm a C++ beginner. Hello.
Not the same format as ifstream in ("C:\~~~~~\"Example.txt").
Stored as string A = "Example.txt",
I wonder if there is a way to write in the same format as ifstream in ("C:\~~~~\A").
I'm leaving a question like this because I can't find it even if I search on Google.
These are the ways that I tried to think about it, like ("C:\~~\Desktop\"G); ("C\~\Desktop"G); or Define. It's all an error.ㅜ<
I wanted to make a program that changes the contents of the file after receiving it, but it's too bad that it's blocked here.ㅜ<
c++ input output
Create a new string with the + operator of string
or
If it is an array of char
, you can use the sprintf
function.
#include <iostream>
#include <fstream>
using namespace std;
char input[512];
int main() {
string file_name = "example.txt";
ifstream inf("./" + file_name);
inf.getline(input, 512);
cout << input << endl;
return 0;
}
© 2024 OneMinuteCode. All rights reserved.