Help me out

Hi, I am a new C++ learner. In my code I am trying to read text from file. As I compiled the code the error message display as
1>------ Build started: Project: practice book assignment, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I don't know how to remove this issue. I am using visual studio express 2010.
Any help would be appreciated.






#include <iostream>
#include <fstream>
#include <string>

using namespace std;

#define FileName 32
bool OpenFile (fstream &in)
{
char file [FileName] = " ";
cout << "enter the file name" << endl;
cin >> file;

in.open(file);

if (in.fail())
{
cout << "CanNot Locate Your File" << endl;

return false;
}
string str;
getline (in,str);

while (!in.eof())

cout << " " << str << endl;
return true;

}

int main ()
{
fstream in;
OpenFile (in);
system ("pause");
return 0;

}
Last edited on
closed account (jwkNwA7f)
Please move to the Beginner's forum. You can do that by clicking "edit topic" at the top of the page. Then, in the combo box, select "Beginner's Programming" instead of "Lounge".
closed account (NUj6URfi)
This should be posted under beginners w/ code tags.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

 #include <iostream>
 #include <fstream>
 #include <string>

 using namespace std;

 #define FileName 32
int OpenFile (fstream &in) {
 char file [FileName] = " ";
 cout << "Enter the file name" << endl;
 cin.getline(file, 100);

 in.open(file);

 if (in.fail()) {
 cout << "Can Not Locate Your File /n";

 return false;
 }

 string str;
 cin.getline (str, 100);

 while (!in.eof()) {

 cout << " " << str << endl;
 return true;

 }

 int main () {
 fstream in;
 OpenFile (in);
 system ("pause");
 return 0;

 }
Why 100?
I mean getline (file, 100); what is 100 represents?
Streamsize, see http://www.cplusplus.com/reference/istream/istream/getline/

After reading that we all realize it to be an error to read up to 100 characters into an array that has space for only 32.
Topic archived. No new replies allowed.