Question:
how do I convert my char code to string in C++?
anonymous
1970-01-01 00:00:00 UTC
how do I convert my char code to string in C++?
Three answers:
?
2012-09-13 14:33:20 UTC
use string objects

and use the += operator



string DNA;

char a='A';

....



DNA+=a;
anonymous
2012-09-13 14:31:21 UTC
// question.cpp : Defines the entry point for the console application.

//



#include "stdafx.h"

#include

#include

#include



using namespace std;



void KeyInput();



int _tmain(int argc, _TCHAR* argv[])

{

KeyInput();

return 0;

}



void KeyInput()

{



string DNAString;

string RNAString;

char OutChar;

unsigned int index;



cout<<"Enter DNA Sequence"<
cin>>DNAString;

for(index=0; index
{



switch(DNAString[index])

{

case 'A':

{

OutChar = 'U';

break;

}

case 'G':

{

OutChar = 'C';

break;

}

case 'C':

{

OutChar = 'G';

break;

}

case 'T':

{

OutChar = 'A';

break;

}

default:

{

//you could add some error code here

OutChar = (char)-1;

break;

}



}

if(OutChar!=(char)-1)

{

RNAString +=OutChar;

cout<
}

}

cout<
cout<


cout<
cout<< DNAString.length() <
fstream myfile;

myfile.open("IOResults.txt", ios::out);

myfile<
myfile.close();



}
godfatherofsoul
2012-09-13 14:04:01 UTC
You can pass a char array to the constructor of string



string dna(DNA);


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...