Hi. I wasbwondering if there was a way to have the user input something to a string and then write that as the filename. Please use my example of the string deckname.

Recommended Answers

All 13 Replies

Of course. Read the string from the user. Use the string as the filename. No magic about it.

Let me change your question and the answer to this is how you wold do the filename thing, too:

Hi. I was wondering if there was a way to have the user input a number into an integer and then use that as a value in an equation.

I was meaning to ask for the code on how to do it.

And I was meaning to tell you how you can do it. We aren't a give-away coding site, you know. You probably need to read the Member Rules as asked.

Sorry i haven't had time to upload my code and that's why you can't help me. I need help making whatever they input for deckname as a filename.

#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include <cstdlib>



int main()
{
using namespace std;

int t;
int randm;
string bck;
string frt; 
string filename;
string deckname;
int a = 1;
int x;
ofstream ledeck;


cout << "Flashcards Creator v.7" << endl;
cout << "1-Create Flashcards" << endl;
cout << "2-Look at Decks" << endl;
cin >> t;
if (t == 1)
{                 
cout << "Enter the deck name of your cards. You must not use spaces." << endl;
cin >> deckname;
ledeck.open(deckname,".txt");
ledeck.close();

cout << "How many study cards do you want?" << endl;
cin >> x;
x;
while (a<=x)
{
cout << "Front of card: (No spaces for these either for now)" << endl;
cin >> frt;
cout << "Back of card:" << endl;
cin >> bck;


randm = 1;
if (randm = 1){
a ++;        
        }}}



else if (t == 2){
cout << "Coming Soon!!!" << endl;
}


else {
cout << "Haha! You're so funny!" << endl;
}







system("pause");
return 0;
}

Ignore my = and not == on the if statements please. Hope you guys can help

The other big problem i have is having input that has a space in it. It screws up the system. So I tried the getline thing and it went right past the command.

Anybody? Help would be great!

Look up the OPEN command again. I believe you have it wrong.

Im using dev c++ btw. All i meed help with is line 32. I attempted to use the string as the filename, but i dont know how. So what is the command for it?

That doesnt answer my question on line 32! Justntell me the command please.

That doesnt answer my question on line 32!

Yes it does. You'll have to tell us why it doesn't. All you have to do is look at your line 32 and compare it to their command.

Justntell me the command please.

We would rather you learn, not just let us do it for you.

Ok, then how do i learn the new command?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.