String Problems

I don't know why this is happening!

Please bear with me if I don't get something as I am only 13.

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
39
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	string filename;
	string longname;
	string gametype;

	cout << "\nWelcome to the Republic Commando Map Updater and Load Updater\n";
	cout << "\nPlease Enter the filename of the map without the file extension\n";
	cin >> filename;
	cout << "\n\nPlease Enter the full name of the map\n";
	cin >> longname;
	cout << "\n\nPlease enter type of game - DM = DeathMatch - TM = Team DeathMatch - \nCTF = Capture the Flag - AS = Assault.\n";
	cin >> gametype;
	
	string str = "\n\nMap=(FileName=\"";
	str.append (filename"\",LongName=\"");
	str.append (longname"\",Screenshot=\"MapThumbnails.DM_Canyon\",Text=\"Xmaps.GEO_CanyonSmall\",IdealPlayerCountMin=1,IdealPlayerCountMax=16,GoalScore=30,TimeLimit=10,FragLimit=10,SupportedGames=\"");
	str.append (gametype"\",bSplitScreenOK=1,bNetworkOK=1");

	ofstream myFile("xmaplist.int", ios:app);

	if (! myFile)
	{
		cout << "Error opening output file" << endl;
		return -1;
	}

	myFile << str << endl;
	myfile.close();

	return 0;
	
}


These are the errors I get:

c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(22) : error C2143: syntax error : missing ')' before 'string'
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(22) : error C2059: syntax error : ')'
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(23) : error C2143: syntax error : missing ')' before 'string'
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(23) : error C2059: syntax error : ')'
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(24) : error C2143: syntax error : missing ')' before 'string'
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(24) : error C2059: syntax error : ')'
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(26) : error C2275: 'std::ios' : illegal use of this type as an expression
1> c:\program files\microsoft visual studio 9.0\vc\include\iosfwd(705) : see declaration of 'std::ios'
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(26) : error C2143: syntax error : missing ')' before ':'
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(26) : error C2448: 'myFile' : function-style initializer appears to be a function definition
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(26) : error C2059: syntax error : ')'
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(28) : error C2065: 'myFile' : undeclared identifier
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(34) : error C2065: 'myFile' : undeclared identifier
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(35) : error C2065: 'myfile' : undeclared identifier
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(35) : error C2228: left of '.close' must have class/struct/union
1> type is ''unknown-type''
On lines 22, 23, and 24 use two backslashes. When you use the string "\" it thinks you are using a quotation mark inside the string. If you want a \ you have to use two of them \\ otherwise the compiler thinks you are trying to use a special code character like \n which is move the cursor to the next line or in your case \" which outputs a "
Yeah but I want quote marks.

I am trying to display this:

Map=(FileName="dm_trainingfacility",LongName="Training Facility",Screenshot="MapThumbnails.DM_Canyon",Text="Xmaps.GEO_CanyonSmall",IdealPlayerCountMin=1,IdealPlayerCountMax=16,GoalScore=30,TimeLimit=10,FragLimit=10,SupportedGames="DM",bSplitScreenOK=1,bNetworkOK=1)

With the obvious bits changed for variables in the code.
You can't just put strings next to one another; that doesn't make them concatenate. You have to add them with the addition operator first.
Whatt tummychow is referring to is using the addition sign to perform an operation called concatenation. Instead of using longname"\",Screensh....
Try: longname + "\",Screensh.......
And maybe you can ditch the append command that way too.
Using the addition sign with the append command solved all the errors but now I get new errors about the part below

Here is my enw code
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
39
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	string filename;
	string longname;
	string gametype;

	cout << "\nWelcome to the Republic Commando Map Updater and Load Updater\n";
	cout << "\nPlease Enter the filename of the map without the file extension\n";
	cin >> filename;
	cout << "\n\nPlease Enter the full name of the map\n";
	cin >> longname;
	cout << "\n\nPlease enter type of game - DM = DeathMatch - TM = Team DeathMatch - \nCTF = Capture the Flag - AS = Assault.\n";
	cin >> gametype;
	
	string str = "\n\nMap=(FileName=\"";
	str.append (filename + "\",LongName=\"");
	str.append (longname + "\",Screenshot=\"MapThumbnails.DM_Canyon\",Text=\"Xmaps.GEO_CanyonSmall\",IdealPlayerCountMin=1,IdealPlayerCountMax=16,GoalScore=30,TimeLimit=10,FragLimit=10,SupportedGames=\"");
	str.append (gametype + "\",bSplitScreenOK=1,bNetworkOK=1");

	ofstream myFile("xmaplist.int", ios:app);

	if (! myFile)
	{
		cout << "Error opening output file" << endl;
		return -1;
	}

	myFile << str << endl;
	myfile.close();

	return 0;
	
}


Here is my new errors
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(26) : error C2275: 'std::ios' : illegal use of this type as an expression
1> c:\program files\microsoft visual studio 9.0\vc\include\iosfwd(705) : see declaration of 'std::ios'
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(26) : error C2143: syntax error : missing ')' before ':'
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(26) : error C2448: 'myFile' : function-style initializer appears to be a function definition
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(26) : error C2059: syntax error : ')'
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(28) : error C2065: 'myFile' : undeclared identifier
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(34) : error C2065: 'myFile' : undeclared identifier
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(35) : error C2065: 'myfile' : undeclared identifier
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\map and load updater\map and load updater\main.cpp(35) : error C2228: left of '.close' must have class/struct/union
please help i have no idea what is wrong as |i am tacking this code out of a book I have usded before with no problems.
I have changed some lines(Bold letters) now it might work
ofstream myFile("xmaplist.int");

if (! myFile)
{
cout << "Error opening output file" << endl;
return -1;
}

myFile << str << endl;
myFile.close();
Topic archived. No new replies allowed.