![]() |
C++ question
i got v0.1a working theres a link in my other thread here.
workin on v0.1b and this line doesnt work :
ofstream myfile2("//"d"//answers.txt");d is a string which was input by user (their name) this is the error :
23 C:\Dev-Cpp\TestApp0.1b\test3-1.cpp expected `)' before "d" |
It looks like you are trying to create a folder with a username with the answers inside it. Make your string combined with "answers.txt" before you create the file. // is a comment, \\ is for file paths.
|
exactly! thanks
now, it still doesnt work when i change // to \\ and if the string combines then it is not in a new folder just a file with a diff. name AND i get an error if i try to specify the path as just a string... so how can i make it so that when the user enters their name a subdir named as the string they just entered in with a .txt is made..... |
i tried combining the strings prm753 but it still wont compile or link
|
I'm a little lost with what you're trying to do, but have you tried the following yet?
:
ofstream myfile2("..\\answers.txt");By the way, your signature is wrong. sqrt(x^2) does not equal x. It equals |x|. Therefore, sqrt((-1)^2) equals |-1|, or 1. |
sqrt(x^2) does not equal x. It equals |x|.
Therefore, sqrt((-1)^2) equals |-1|, or 1. I would say Sane saved the world from being overrun by thousands of mad math teachers! |
i know its wrong...its a joke (sorry if it was too simple)
anyway sane, thats not what im tryin to do. i am trying to specify the file path using a string of what the user entered as his name plus answer.txt. and it doesnt work. evidently i cannot specify a file name in the fstream parameter as a variable representing a string.... |
Quote:
Also try to make your topic titles a bit more informative, we can guess that it is a "C++ question" as it is in the C++ forum. Maybe something like "how to add strings together" or "how do I get the user to input a directory". Similarly, your other topic "new question now" is just as uninformative. |
Another problem is that you are trying to pass the open() function a string, when in actual fact it takes a character array const char *. So either use a character array to store your file path, or use the c_str() member function of your current string to convert it to a char array.
for example: :
string filepath = "C:\\"; |
ok this compiles fine but when i enter the name it jsut freezes...
:
#include <cstdlib> |
| All times are GMT -5. The time now is 1:09 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC