I am having trouble trying to merge 2 strings into 1. Is this possible if so how is it done?

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 3 Years Ago by happygeek: fixed formatting

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");		
	}

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?

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?

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 article has been dead for over six months. Start a new discussion instead.