I've tried strcat, but it wouldn't let me do it cause the 2nd peramiter needed to be a const char
I've tried strcat, but it wouldn't let me do it cause the 2nd peramiter needed to be a const char
string::c_str() returns the char* of the std::string
Hey, for what your doing, just use this:
This is the easiest way to accomplish the task you are doing.Code:#include <iostream.h> #include <fstream.h> #include <string.h> main() { char x; string current; //change to string ifstream infile; infile.open("text.txt",ios::in); while(infile) { infile.get(x); current += x; } return 0; }
when I did that, this is the errors I got:
I did exactly what you did, any more ideas on what's going on?Code:"\readtxt.cpp(10) : error C2065: 'string' : undeclared identifier" "\readtxt.cpp(10) : error C2146: syntax error : missing ';' before identifier 'current'" "\readtxt.cpp(10) : error C2065: 'current' : undeclared identifier"
did you include string.h?
Regards,
Mario Figueiredo
Using Borland C++ Builder 5
Read the Tao of Programming
This advise was brought to you by the Comitee for a Service Packless World
sure did
What is the C++ compiler that you have ?
C++
The best
thanks for all your guys' help, I got to work
YAY for me
Last edited by Agent89; 06-04-2002 at 03:02 PM.
Newbie @ Work
So what was the problem? I'm curious.
I'm not really sure.
What I did was did a seperate infile.get and then I was able to strcmp them. I don't know exactly, it's at school, I'll let you know more tomorrow
Newbie @ Work
All right, thanx. I'd really like to know.
When you're dealing with arrays to store data in almost any situation, a loop is always the answer. To quot from one of the greatest films of all time, the advice of Dr. Leo Marvin, Bob Wiley's, psichiatrist:
Baby steps. Don't think of how you're going to get out of this building, concentrate on how you're going to get out of this room. And once you're in the hall, deal with that hall, and so on.
That's a funny movie..
yeah, I'll post my code that works on thursday
Newbie @ Work
Code:#include <iostream.h> //Original Idea for question code By Jeremy Jones #include "apstring.h" #include <fstream.h> #include <string.h> int main() { char x; char answer[20]; ifstream infile; char correct[13]; bool answered; infile.open("trivia.dat", ios::in); //opens the file while (infile.get(x)) { if(x == '|') //pauses the file read for the user to answer { cin >> answer; answered = true; //sets the boolian for the fact that the user has answered the question } else { cout << x; } if(answered == true) //this checks to see if the user has answered the question. { infile.get(correct,13); //grabs the characters infile.ignore(80,'\n'); //puts them into a string if(!strcmp(correct,answer)) //this checks ifthe user answer is correct. { cout<<"\nCorrect!!\n"; //tells the user he's right } else { cout << "\nSorry, that's incorrect\n"<<endl; //tells the unfortunate user the bad news } } } return 0; }
Newbie @ Work