文字列変数をCreateDirectoryに挿入する方法はありますか?ユーザーが入力した名前でC:にディレクトリを作成したいと思います。私が何かをするとき
CreateDirectory ("C:\\" << newname, NULL);
私のコンパイラは、「'C:\<<newname'のoperator<<に一致しません」というエラーを表示します。
これは私のコードです。問題はvoidnewgame()にあります。
#include <iostream>
#include <fstream>
#include <string>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <mmsystem.h>
#include <conio.h>
using namespace std;
int a;
string newname;
string savepath;
struct game
{
string name;
int checkpoint;
int level;
};
void wait( time_t delay )
{
time_t timer0, timer1;
time( &timer0 );
do {
time( &timer1 );
} while (( timer1 - timer0 ) < delay );
}
void error()
{
cout << "\nError, bad input." << endl;
}
void options()
{
cout << "No options are currently implemented." << endl;
}
void load()
{
cout << "Load a Game:\n";
}
//This is where I'm talking about.
void newgame()
{
cout << "Name your Game:\n";
getline(cin,newname);
cin.get();
game g1;
g1.name=newname;
//I want it to create a dir in C: with the name the user has entered.
//How can I do it?
CreateDirectory ("C:\\" << newname, NULL);
}
//This isn't the whole piece of code, just most of it, I can post the rest if needed