Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

Anonymous

unregistriert

1

09.01.2009, 22:40

.txt-Datei in das Programm laden?

Hallo,

ich habe lange über Google nach Lösungen gesucht, damit, wenn man in der Projektmappe "Übungsprogramm" eine neue .txt-Datei macht, die man in das Programm laden kann.
Also kurz gesagt:

.txt-Datei in Projektmappe erstellen -> "abc" reinschreiben -> laden (Code [C++]) -> Bildschirmausgabe -> abc


Dient zur Übersichtlichkeit.

drakon

Supermoderator

Beiträge: 6 513

Wohnort: Schweiz

Beruf: Entrepreneur

  • Private Nachricht senden

2

09.01.2009, 22:47

http://www.cplusplus.com/reference/iostream/ifstream/

Oder wo ist genau das Problem?

Anonymous

unregistriert

3

09.01.2009, 22:48

Zitat von »"drakon"«

http://www.cplusplus.com/reference/iostream/ifstream/

Oder wo ist genau das Problem?


Hab ich schon nachgeschaut, ich vesteh' kein englisch, mit überstezer hab ichs auch schon versucht, doch dann wirds bruchdeutsch, sodass man nichts mehr verstehen kann.

drakon

Supermoderator

Beiträge: 6 513

Wohnort: Schweiz

Beruf: Entrepreneur

  • Private Nachricht senden

4

09.01.2009, 22:50

Dann halt mit google auf Deutsch versuchen:
http://www.google.ch/search?hl=de&client=firefox-a&rls=org.mozilla%3Ade%3Aofficial&hs=YUP&q=ifstream&btnG=Suche&meta=lr%3Dlang_de

Anonymous

unregistriert

5

09.01.2009, 22:53

Zitat von »"drakon"«

Dann halt mit google auf Deutsch versuchen:
http://www.google.ch/search?hl=de&client=firefox-a&rls=org.mozilla%3Ade%3Aofficial&hs=YUP&q=ifstream&btnG=Suche&meta=lr%3Dlang_de


Habs gerade damit versucht:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// ifstream::is_open

#include <iostream>
#include <fstream>
using namespace std;

int main () {

  ifstream infile;
  infile.open ("test.txt");
  if (infile.is_open())
  {
    while (infile.good())
      cout << (char) infile.get();
    infile.close();
  }
  else
  {
    cout << "Error opening file";
  }
  return 0;
}


Meine datei heißt "test.txt". in der datei steht abc. was rauskommt ist das:



Nix da? Dann markiers mal -.- n Leerzeichen -.-

drakon

Supermoderator

Beiträge: 6 513

Wohnort: Schweiz

Beruf: Entrepreneur

  • Private Nachricht senden

6

09.01.2009, 22:56

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main () {

  ifstream infile ("test.txt");    
  std::string s;
  
  infile >> s;
  cout << s;

  return 0;
}

Anonymous

unregistriert

7

09.01.2009, 22:58

Zitat von »"drakon"«

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main () {

  ifstream infile ("test.txt");    
  std::string s;
  
  infile >> s;
  cout << s;

  return 0;
}



Jetz kommt nic mehr.

8

09.01.2009, 23:07

Zitat

Jetz kommt nic mehr.

??

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
    fstream f("test.txt", ios::in);
    string s;

    while(getline(f, s))
        cout << s << endl;
}

Anonymous

unregistriert

9

09.01.2009, 23:10

Oder...

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main () 
{

  ifstream infile ("test.txt");   
  std::string s;
 
  //Wenn mehrzeilig

  while(!infile.eof())
 {
   getline(infile,s);
   cout<< s;
 }

  return 0;
}

Anonymous

unregistriert

10

09.01.2009, 23:11

Zitat von »"defaultplayer^^

Zitat

Jetz kommt nic mehr.

??

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
    fstream f("test.txt", ios::in);
    string s;

    while(getline(f, s))
        cout << s << endl;

                return 0;
}


sry, bei ir kommt trotzdem noch:

"Appuyez sur une touche pour continuer..."

raus.

Werbeanzeige