Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 22:48

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C++]Variable in fstream öffnen

Discussion on [C++]Variable in fstream öffnen within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
Masterakio1995's Avatar
 
elite*gold: 8
Join Date: Apr 2009
Posts: 2,977
Received Thanks: 855
[C++]Variable in fstream öffnen

Wo ist hier der fehler?
Quote:
save2 = save2 + ".txt";
data.open(save2, ios:ut);
Masterakio1995 is offline  
Old 07/30/2010, 12:22   #2
 
elite*gold: LOCKED
Join Date: Aug 2006
Posts: 3,292
Received Thanks: 866
Was zeigt denn der Debugger als Fehler an?

<-- am besten noch mal anschauen
scenebase is offline  
Old 07/30/2010, 13:02   #3
 
vst0rm's Avatar
 
elite*gold: 0
Join Date: Jul 2010
Posts: 56
Received Thanks: 12
wenn dein save2 ein string class object ist dann sollte es so gehen ^^

PHP Code:

string save2 
"hallo";
fstream data;

save2 += ".txt";

data.open(save2ios::out);

if(
data.is_open())
    
cout <<save2.data()<<endl
vst0rm is offline  
Old 07/31/2010, 22:58   #4
 
Masterakio1995's Avatar
 
elite*gold: 8
Join Date: Apr 2009
Posts: 2,977
Received Thanks: 855
Funktioniert auch nicht
Quote:
In function `int main()':

no matching function for call to `std::basic_fstream<char, std::char_traits<char> >:pen(std::string&, const std::_Ios_Openmode&)'

note C:\Dev-Cpp\include\c++\3.4.2\fstream:819 candidates are: void std::basic_fstream<_CharT, _Traits>:pen(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
Masterakio1995 is offline  
Old 08/01/2010, 12:01   #5
 
vst0rm's Avatar
 
elite*gold: 0
Join Date: Jul 2010
Posts: 56
Received Thanks: 12
hmm zeig mal deinen source code
vst0rm is offline  
Old 08/01/2010, 16:41   #6
 
Masterakio1995's Avatar
 
elite*gold: 8
Join Date: Apr 2009
Posts: 2,977
Received Thanks: 855
Hier:
Quote:
#include <iostream>
#include <fstream>

using namespace std;

int main() {
string save2 = "hallo";
fstream data;

save2 += ".txt";

data.open(save2, ios:ut);

if(data.is_open())
cout <<save2.data()<<endl;
system("pause");
}
Masterakio1995 is offline  
Old 08/01/2010, 18:42   #7
 
vst0rm's Avatar
 
elite*gold: 0
Join Date: Jul 2010
Posts: 56
Received Thanks: 12
Quote:
Originally Posted by Masterakio1995 View Post
Hier:
Zitat:
#include <iostream>
#include <fstream>

using namespace std;

int main() {
string save2 = "hallo";
fstream data;

save2 += ".txt";

data.open(save2, ios:ut);

if(data.is_open())
cout <<save2.data()<<endl;
system("pause");
}
also dein Code funktioniert bei mir tadellos (visual c++ 2010)

vieleicht mal das probieren

PHP Code:
data.open(save2ios_base::out);
//anstatt
data.open(save2ios::out); 
vst0rm is offline  
Old 08/01/2010, 19:47   #8
 
Masterakio1995's Avatar
 
elite*gold: 8
Join Date: Apr 2009
Posts: 2,977
Received Thanks: 855
nein immernoch nicht -.-"
Masterakio1995 is offline  
Old 08/01/2010, 20:25   #9
 
vst0rm's Avatar
 
elite*gold: 0
Join Date: Jul 2010
Posts: 56
Received Thanks: 12
oki habs noch mal mit nem g++ compiler versucht

PHP Code:
data.open(save2.c_str(), ios::out); 
so sollte es klappen
vst0rm is offline  
Old 08/01/2010, 20:35   #10
 
Masterakio1995's Avatar
 
elite*gold: 8
Join Date: Apr 2009
Posts: 2,977
Received Thanks: 855
dankeschön kannst du mir eventl auch erklären warum das jetzt klappt?
Masterakio1995 is offline  
Old 08/01/2010, 20:52   #11
 
elite*gold: 20
Join Date: Sep 2006
Posts: 1,100
Received Thanks: 184
Im Compiler Fehler steht doch schon was das Problem ist...
Die Member Funktion open von fstream ist nicht für std::string überladen, warum das in VC++ funktioniert ist mir ein Rätsel, vielleicht eine nicht dokumentierte Erweiterung von MS, in der msdn Library ist jeden Falls nichts dazu zu finden.
Code:
data.open(save2.c_str(), ios::out);
sollte funktionieren.
Bot_interesierter is offline  
Old 08/01/2010, 22:25   #12
 
Masterakio1995's Avatar
 
elite*gold: 8
Join Date: Apr 2009
Posts: 2,977
Received Thanks: 855
trotzdem würde mich intressieren warum das mit save2.c_str() geht
Masterakio1995 is offline  
Old 08/01/2010, 23:50   #13
 
xNopex's Avatar
 
elite*gold: 0
Join Date: May 2009
Posts: 827
Received Thanks: 471
Quote:
Code:
fstream::open
void open ( const char * filename,
            ios_base::openmode mode = ios_base::in | ios_base::out );

Quote:
Code:
string::c_str()
const char* c_str ( ) const;
Quelle:


Alles klar?
xNopex is offline  
Old 08/02/2010, 00:04   #14


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,904
Received Thanks: 25,394
Quote:
Originally Posted by Masterakio1995 View Post
trotzdem würde mich intressieren warum das mit save2.c_str() geht
Wurde doch schon gesagt, weil keine Version für std::string existiert, nur für const char.

std::string::c_str() gibt genau so einen zurück.
MrSm!th is offline  
Old 08/02/2010, 10:31   #15
 
Masterakio1995's Avatar
 
elite*gold: 8
Join Date: Apr 2009
Posts: 2,977
Received Thanks: 855
ok dankeschön
Masterakio1995 is offline  
Reply


Similar Threads Similar Threads
GUI-Input als Variable.
06/20/2010 - AutoIt - 8 Replies
Hey, ich habe mit KODA eine Inputbox erstellt, möchte nun aber dass ich das was ich in die Inputbox eintrage dann per 'OK'-Knopfdruck im schon vorher geöffnetem Notepad geschrieben wird. #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form3 = GUICreate("Test", 116, 82, 303, 219) $Button1 = GUICtrlCreateButton("&OK", 8, 48, 99, 25) GUICtrlCreateInput("", 16, 16, 81, 21) GUISetState(@SW_SHOW)
Error Variable used .....
05/26/2010 - AutoIt - 3 Replies
Hi, #include <NomadMemory.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 625, 445, 193, 125)
Username in Variable
04/01/2010 - AutoIt - 2 Replies
Hallo, ich wollte ein kleines Programm für meine jüngere Cousine anfertigen, denn sie hat viel Spaß an solchen Programmen ;) Und zwar möchte ich zuerst eine InputBox erscheinen lassen, inder nach dem Namen gefragt wird. Danach soll sich eine MsgBox öffnen, wo steht: Herzlich Willkommen ... ( ... = der Name) So siehts im Moment aus. $input1 = InputBox("Hallo", "Hallöchen! Bevor es losgehen kann, &CRLF möchte ich gern wissen, wie du heißt.") MsgBox("Herzlich Willkommen", "Herzlich...
Variable und down/up befehl
09/23/2009 - AutoIt - 0 Replies
Hallo! Also ich habe folgendes Problem: Ich will meine variable ($taste1) und den "{down}" tastendruck ausführen aber wie krieg ich das hin also möchte das die variable taste1 runtergedrückt wird bis ich sie wieder mit "{up}" loslasse. Allerdings weis ich es bei up auch nicht Mein script sieht bisher so aus Send($taste1 "{down}") Thx schonmal in vorraus:confused::( ok habs jetzt nach langer zeit =) ich hab es einfach über eine if schleife gemacht Ok Funktioniert doch net hat keiner...
How do I add a variable
08/21/2009 - CO2 Private Server - 4 Replies
Couldn't find a guide when I searched. I want to make a variable so it will check how many times the player has already used unknown man. I know how to use the variable, but just don't know how to make it. Oh yea this is LOTF



All times are GMT +2. The time now is 22:48.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.