Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Reading from a text file, netbeans c++?

Reply
Thread Tools

Reading from a text file, netbeans c++?

 
 
I
Guest
Posts: n/a
 
      10-11-2012
Hello All,

Does anyone know how and/or where to add a text file if I want to practice reading in text using Netbeans C++?

Thanks
Ian

code:

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cstdlib>

using namespace std;

int main()
{
int sum=0, count;
ifstream test;
ifstream readin;
std::string tester;
test.open("Alligator.txt");
//test.open("C:\\Users\\Ian\\C++\\Text\\Alligator.tx t");
if(!test.is_open())
{
cout<<"Error opening file!";
exit(EXIT_FAILURE);
}
char test_array[100];
test.getline(test_array,100);
//cout<<test_array;
//getline(test,tester);
while(test.good())
{
//cout<<tester<<endl;
++sum;
//getline(test,tester);

}
if(test.eof())
cout<<"End of file reached!\n";
else if(test.fail())
cout<<"Error of the unknown type?\n";
cout<<sum;
system("pause");
return 0;
}
 
Reply With Quote
 
 
 
 
Kuroneko
Guest
Posts: n/a
 
      10-12-2012
On Thursday, 11 October 2012 17:38:21 UTC-4, I wrote:
> Hello All,
>
>
>
> Does anyone know how and/or where to add a text file if I want to practice reading in text using Netbeans C++?
>
>
>
> Thanks
>
> Ian
>
>
>
> code:
>
>
>
> #include <iostream>
>
> #include <fstream>
>
> #include <string>
>
> #include <cstring>
>
> #include <cstdlib>
>
>
>
> using namespace std;
>
>
>
> int main()
>
> {
>
> int sum=0, count;
>
> ifstream test;
>
> ifstream readin;
>
> std::string tester;
>
> test.open("Alligator.txt");
>
> //test.open("C:\\Users\\Ian\\C++\\Text\\Alligator.tx t");
>
> if(!test.is_open())
>
> {
>
> cout<<"Error opening file!";
>
> exit(EXIT_FAILURE);
>
> }
>
> char test_array[100];
>
> test.getline(test_array,100);
>
> //cout<<test_array;
>
> //getline(test,tester);
>
> while(test.good())
>
> {
>
> //cout<<tester<<endl;
>
> ++sum;
>
> //getline(test,tester);
>
>
>
> }
>
> if(test.eof())
>
> cout<<"End of file reached!\n";
>
> else if(test.fail())
>
> cout<<"Error of the unknown type?\n";
>
> cout<<sum;
>
> system("pause");
>
> return 0;
>
> }


Put it in the same directory as the compiled binary. (I think.)
 
Reply With Quote
 
 
 
 
I
Guest
Posts: n/a
 
      10-14-2012
Turns out just had to list the target directory. Thanks though!

On Thursday, October 11, 2012 8:10:46 PM UTC-5, Kuroneko wrote:
> On Thursday, 11 October 2012 17:38:21 UTC-4, I wrote:
>
> > Hello All,

>
> >

>
> >

>
> >

>
> > Does anyone know how and/or where to add a text file if I want to practice reading in text using Netbeans C++?

>
> >

>
> >

>
> >

>
> > Thanks

>
> >

>
> > Ian

>
> >

>
> >

>
> >

>
> > code:

>
> >

>
> >

>
> >

>
> > #include <iostream>

>
> >

>
> > #include <fstream>

>
> >

>
> > #include <string>

>
> >

>
> > #include <cstring>

>
> >

>
> > #include <cstdlib>

>
> >

>
> >

>
> >

>
> > using namespace std;

>
> >

>
> >

>
> >

>
> > int main()

>
> >

>
> > {

>
> >

>
> > int sum=0, count;

>
> >

>
> > ifstream test;

>
> >

>
> > ifstream readin;

>
> >

>
> > std::string tester;

>
> >

>
> > test.open("Alligator.txt");

>
> >

>
> > //test.open("C:\\Users\\Ian\\C++\\Text\\Alligator.tx t");

>
> >

>
> > if(!test.is_open())

>
> >

>
> > {

>
> >

>
> > cout<<"Error opening file!";

>
> >

>
> > exit(EXIT_FAILURE);

>
> >

>
> > }

>
> >

>
> > char test_array[100];

>
> >

>
> > test.getline(test_array,100);

>
> >

>
> > //cout<<test_array;

>
> >

>
> > //getline(test,tester);

>
> >

>
> > while(test.good())

>
> >

>
> > {

>
> >

>
> > //cout<<tester<<endl;

>
> >

>
> > ++sum;

>
> >

>
> > //getline(test,tester);

>
> >

>
> >

>
> >

>
> > }

>
> >

>
> > if(test.eof())

>
> >

>
> > cout<<"End of file reached!\n";

>
> >

>
> > else if(test.fail())

>
> >

>
> > cout<<"Error of the unknown type?\n";

>
> >

>
> > cout<<sum;

>
> >

>
> > system("pause");

>
> >

>
> > return 0;

>
> >

>
> > }

>
>
>
> Put it in the same directory as the compiled binary. (I think.)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Eclipse vs. Netbeans. Netbeans is winning me over almost at first glance. Thomas G. Marshall Java 2 10-16-2006 02:54 AM
[NETBEANS] [EVALUATION] - E12 - The NetBeans Open Source Lie Ilias Lazaridis Java 0 12-12-2004 02:41 PM
reading the DB vs. reading a text file...performance preference? Darrel ASP .Net 3 11-11-2004 02:27 PM
Building a GUI using NetBeans platform (not Netbeans IDE !) Pimousse Java 2 04-21-2004 07:22 AM
NetBeans + Mac - Text in Source Editor is very light (aliased) Leonard Slatkin Java 0 11-01-2003 06:11 PM



Advertisments