Give me a hand please!

I am JUST A BEGINNER IN C++ (a week) and I’d like to get help (given the following)
#include <iostream>
#include <fstream>
using namespace std;
int main( int argc, char* argv[] ) {
ifstream infile( argv[1] );
char ch = 0;
while( infile.get( ch ) ) {
cout.put( ch );
}
return 0;
}
How can I Create a C++ console application that locates all C/C++ string literals from a C++ source file and prints the filename followed by the line number that the string is located on, a colon, a space then the quoted string. Repeat the string line for each string in the file.
The program will read source code from the console and output the strings to the console.
The executable file must be named ‘stringfinder.exe’
THANKS A LOT IN ADVANCE!
millanjn@gmail.com
Last edited on
This forum is not a homework service. You should work on the code yourself and ask for help with specific problems.
http://www.cplusplus.com/forum/beginner/11333/

Are you two on the same class?
Thank you Zhuge, this is a nice answer for a just born into this field. It is greatly appreciated!
Helios thanks a lot for the link! What a difference!
Im having a Hard time understanding your question, + use code tags.
But if your trying to search a file and find line numbers i guess you could do this.

maybe somethin along the lines of this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
fstream FILE(blahblah,ios::app)
string line = "";
int count  = 0;
string search = "CoorsLight"; //search word
while(getline(FILE,line,'#'))
{
count++ // counts every line in file
if(line == search)
{
// grab the count .. this will equal the line number
// then output your string here by FILE<< youText;
}
}
FILE.close();

mioro thinks that he can post some random code and have people do his work for him. Too bad there are so many posers studying comp. sci. In another five years, our software will instigate nuclear war for us, because some loser wannabe who cheated his way through class went and modified some program he shouldn't have had modification rights to -- since he had to lie to get the job doing things he didn't understand anyway.

Oh, and in the meantime, those of us who actually know what we are doing have to put up with his arrogant, obnoxious, rude, and self-gratifying crap.

Too bad you can't call black black anymore.
^
|
|
|

What the HELL was that!
The OP has violated almost all of the major rules of netiquette when posting.

Basically, he posted saying

"Boo-hoo woe is me! I've got a homework problem I can't do because I'm too lazy or because I haven't paid enough attention in class. Now I'm going to get a bad grade.

Please someone write it for me. Oh, and send it to loser@gmail.com."

Zhuge responded exactly right: make an effort, post some real work, identify actual problems, ask for assistance in learning, etc -- and sure, we'll help.

helios likewise was even a bit more helpful -- pointing him to another thread on the exact same assignment (where Ima noob at least made some effort and showed that he was thinking about the problem).

The OP's response was negative: "What? You aren't just going to give me the answer? *insert favorite explicative* to you!"


Real hackers resent such arrogance. ESR has even gone to the lengths of writing a short treatise on the subject: How To Ask Questions The Smart Way -- this is oft-linked and simply-put, just plain part of standard knowledge.
http://catb.org/esr/faqs/smart-questions.html

Our very own forum has an abridged version stickied:
http://www.cplusplus.com/forum/articles/1295/


I must admit, however, I was in a rather foul mood when responding last.
I must admit, however, I was in a rather foul mood when responding last.
Nah. I would have replied similarly if I hadn't decided to just ignore him for being such an asshole after i actually tried to help him. The only difference would have been that I take less time to say "fuck you". Those people don't deserve more of my time even for insulting them.
Last edited on
This will have everything you will ever need!!

http://lmgtfy.com/?q=ifstream
Last edited on
Topic archived. No new replies allowed.