fattumsdad
asked on
Console - Read Text File
Let's say I have a text file called "Test.txt". In this text file, there are numerous lines containing punctuation, numbers, etc. How do I read that file and display it in the console?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>Do I have to link to a lib?
No, just set up your project to link a console app, not a GUI app :o)
>>As for the special formatting, is there a way to read it in exactly as it appears in the text file?
That's wht the above code fragment does. The only difference will be the line wrap when a line exceeeds the console width.
No, just set up your project to link a console app, not a GUI app :o)
>>As for the special formatting, is there a way to read it in exactly as it appears in the text file?
That's wht the above code fragment does. The only difference will be the line wrap when a line exceeeds the console width.
ASKER
This is really strange.... I have it set up as Win32 Console Application... the same setting that I've been using the other million times you've helped me LOL. Still getting the same error... :\
Check again - it might just be something simple :o)
ASKER
I have it in exactly as you showed... should I add:
int main()
{
CoutTextFile("c:/Test.txt" );
return 0;
}
int main()
{
CoutTextFile("c:/Test.txt"
return 0;
}
OMG
Yes.
Yes.
Sorry - I have been following this question and I am disgusted in myself that I did not spot that that was the problem. I did not mean any offence to you :)
Back to the books for me :)
Back to the books for me :)
>> CoutTextFile("c:/Test.txt" );
Probably better to be CoutTextFile("c:\\Test.txt ");
Probably better to be CoutTextFile("c:\\Test.txt
ASKER
Got it. It seems to work the same both ways, "c:/" or "c:\\"... is there a significant difference?
>>It seems to work the same both ways, "c:/" or "c:\\"... is there a significant difference?
No, not at all. Both are valid on Win32 platforms.
No, not at all. Both are valid on Win32 platforms.
Not really. Sometimes a backslash is preferred, but if you do you must use two (\\) as \ is an escape character.
Ta for the assist.
Ta for the assist.
ASKER
Ok... one more question... actually, I'll repost to give more points :) Thank for the help guys!
Glad to help.
ASKER
Do I have to link to a lib? I get:
C:\MinGWStudio\MinGW\bin\.
As for the special formatting, is there a way to read it in exactly as it appears in the text file?