2
Contributors
5
Replies
6
Views
11 Years
Discussion Span
Last Post by Dave Sinkula
0

Do you mean concatenation? Are you using std::string or C-style strings (or other)? Can you post the code of you attempt that you are having trouble with (within CODE tags)?

Edited by happygeek: fixed formatting

0
int main()
{
	string1 username;						
	string2 .txt;
	string3 = string1 + string2;
	
	cout << "Marking Program";				//Start of program


	cout << "Enter Students Username:";		//Get username off program user
	cin >> username;
	
	ifstream in("checkUserName.txt");		
	string search;								string line;
	int n = 0;

	if (!in) {
    cerr<<"Username not found"<<endl;		
    return EXIT_FAILURE;					
	}
	else 
	if (in){
		ifstream in ("string3");		
	}
0

You have some major syntax issues here.

string1 username;
   string2 .txt;

You can't start a variable name with .. You are using string1 and string2 as though they are types; do you mean for each to be a string?

0

To be honest I am not sure. What I am trying to do is open a file using the username that the program operator has entered, does that make sense?

0

That sounds something like this.

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

int main()
{
   cout << "Marking Program\n\n";          //Start of program

   string username;
   cout << "Enter Students Username:";    //Get username off program user
   cin  >> username;

   string filename = username + ".txt";
   ifstream file(filename.c_str());
   if ( !file )
   {
      cerr<<"Username not found"<<endl;
      return EXIT_FAILURE;
   }
   
   // ...
   
   return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.