Problem bei Programm
Hallo,
Ich bin nicht sehr erfahren mit Programmierung und möchte ein programm "basteln".
ich möchte gerne zwei codes zusammenbekommen dafür muss die Ausgabe des 1. Codes als char array verfügbar, sein leider habe ich keine ahnung wie.
1. Code
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
int main()
{
std::vector<std::string> vec;
std::string line;
std::ifstream infile("123.txt");
while(std::getline(infile, line, '\n')) {
vec.push_back(line);
}
for(size_t i = 0; i < vec.size(); i++) {
std::cout << vec[i] << std::endl;
}
system ("pause");
return 0;
}
Die Ausgabe dieses Codes soll dann in diesen Code als Variable eingebaut werden
2. Code
#include<iostream>
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
int rename( char const * oldName, char const * newName );
int main()
{
char Nachricht[100];
cin.getline(Nachricht,100); Nachricht wird eingelesen
for(int i=0;i<strlen(Nachricht);i++) Nachricht aus array auslesen
{
cout<<Nachricht[i];
}
char const * oldName = "HR.txt";
char const * newName = Nachricht;
if( !rename( oldName, newName ) )
printf( "Datei '%s' wurde in '%s' umbenannt.\n", oldName, newName );
else
printf( "Datei '%s' konnte nicht in '%s' umbenannt werden.\n", oldName, newName );
system("pause");
return 0;
}
Der Sinn dahinter ist Folgender:
Es soll aus einer .txt der Inhalt ausgelesen werden und dieser Inhalt als Dateiname verwendet werden.
Ich hoffe ihr könnt mir helfen.
Zur info ich arbeite mit der Aktuellen Microsoft Express Edition C++
Danke im Voraus
1. Code
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
int main()
{
std::vector<std::string> vec;
std::string line;
std::ifstream infile("123.txt");
while(std::getline(infile, line, '\n')) {
vec.push_back(line);
}
for(size_t i = 0; i < vec.size(); i++) {
std::cout << vec[i] << std::endl;
}
system ("pause");
return 0;
}
Die Ausgabe dieses Codes soll dann in diesen Code als Variable eingebaut werden
2. Code
#include<iostream>
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
int rename( char const * oldName, char const * newName );
int main()
{
char Nachricht[100];
cin.getline(Nachricht,100); Nachricht wird eingelesen
for(int i=0;i<strlen(Nachricht);i++) Nachricht aus array auslesen
{
cout<<Nachricht[i];
}
char const * oldName = "HR.txt";
char const * newName = Nachricht;
if( !rename( oldName, newName ) )
printf( "Datei '%s' wurde in '%s' umbenannt.\n", oldName, newName );
else
printf( "Datei '%s' konnte nicht in '%s' umbenannt werden.\n", oldName, newName );
system("pause");
return 0;
}
Der Sinn dahinter ist Folgender:
Es soll aus einer .txt der Inhalt ausgelesen werden und dieser Inhalt als Dateiname verwendet werden.
Ich hoffe ihr könnt mir helfen.
Zur info ich arbeite mit der Aktuellen Microsoft Express Edition C++
Danke im Voraus
Please also mark the comments that contributed to the solution of the article
Content-Key: 183193
Url: https://administrator.de/contentid/183193
Printed on: April 25, 2024 at 01:04 o'clock
3 Comments
Latest comment
Die Lösung ist eigentlich so trivial, das Du da einfach selbst drauf kommen kannst. Falls es Probleme gibt poste den Code und die Fehlerbeschreibung, aber benutze dann auch die Formatting instructions in the posts.