•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 392,070 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,270 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 357 | Replies: 21
![]() |
•
•
Join Date: Jun 2008
Posts: 71
Reputation:
Rep Power: 1
Solved Threads: 0
Hello, I am having a small problem because I have to have to have it so the user can enter a number and that number is stored in a variable and that variable becomes the name of the file to be created with the extension .asw. It is going to be a custom encrypted file. Just need to know what is wrong because I am getting an error right now.
The error is
cout << "Enter the Item ID: \n"; string ItemID; cin >> ItemID; ofstream ItemFile; ItemFile.open(ItemID.c_str()".asw"); ItemFile.close();
The error is
error: expected `)' before string constant| •
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,562
Reputation:
Rep Power: 36
Solved Threads: 860
You formed the string incorrectly
ItemFile.open((string)(ItemID+".asw").c_str()); Last edited by Ancient Dragon : 32 Days Ago at 10:41 am.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
•
•
You formed the string incorrectly
ItemFile.open((string)(ItemID+".asw").c_str());
The result of operator+ for std::string is always going to be a new std::string of the same type, so your cast is redundant. This is cleaner:
cplusplus Syntax (Toggle Plain Text)
ItemFile.open((ItemID + ".asw").c_str());
Member of: Beautiful Code Club.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,562
Reputation:
Rep Power: 36
Solved Threads: 860
You must have mistyped something -- Narue's version works ok, mine doesn't. So post code so we can see what you did
Last edited by Ancient Dragon : 31 Days Ago at 12:18 pm.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: Jun 2008
Posts: 71
Reputation:
Rep Power: 1
Solved Threads: 0
now I have only 1 error left and its from this part of the code
it says that 'file' was not declared in the scope. Any help appreciated.
ofstream file; file.open((ItemIDd + ".asw").c_str());
it says that 'file' was not declared in the scope. Any help appreciated.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,562
Reputation:
Rep Power: 36
Solved Threads: 860
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- Using variable as filename (C++)
- repeat region into declared variable (jmail body) (ASP)
- Problem with string variable in void prnt function (C++)
- Defining Variable problem (Visual Basic 4 / 5 / 6)
- how do you set a variable to be a filename? (C)
Other Threads in the C++ Forum
- Previous Thread: Iterate a 2D vector
- Next Thread: Call Other Forms



Linear Mode