有没有办法将字符串变量插入 CreateDirectory?我希望它使用用户输入的名称在 C: 中创建一个目录。当我做类似的事情时
CreateDirectory ("C:\\" << newname, NULL);
我的编译器给了我错误“'C:\ << newname'中的运算符<<不匹配”
这是我的代码。问题出在 void newgame() 中。
#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