Here is my code for trying to have the charcter variable equal the first character in the string.
Expand|Select|Wrap|Line Numbers
- #include <fstream>
- #include <iostream>
- #include <string>
- using namespace std;
- void CommentEvaluation(string codeArray[], int size, ofstream& dataOut);
- int main()
- {
- int size=0;
- ifstream dataIn;
- ofstream dataOut;
- string codeArray[1000];
- string temp;
- dataIn.open("someProgram.cpp");
- dataOut.open("someProgram.txt");
- while(!dataIn.eof())
- {
- while (size<1000)
- {
- getline(dataIn, temp);
- codeArray[size]=temp;
- size++;
- }
- }
- CommentEvaluation(codeArray, size, dataOut);
- cout << codeArray[size];
- return 0;
- }
- void CommentEvaluation(/* in */ string codeArray[], int size, ofstream& dataOut)
- //This function computes the ratio of total lines of code
- //to the number of comment lines, and ratio of total number
- //of non comment and non blank lines to the total
- //number of code.
- //Preconditions:codeArray is defined and has values
- //Postconditions: output is sent to file
- {
- int counter=0;
- int arrayNumber=0;
- char firstChar;
- int commentTotal=0;
- int lineTotal=0;
- int codeTotal=0;
- float commentRatio;
- float codeRatio;
- while (counter != size)
- {
- firstChar=codeArray[arrayNumber];
- if (firstChar == '/')
- {
- commentTotal++;
- lineTotal++;
- }
- else
- {
- lineTotal++;
- if (firstChar != ' ')
- codeTotal++;
- }
- counter++;
- arrayNumber++;
- }
- commentRatio= commentTotal/lineTotal;
- codeRatio= codeTotal/lineTotal;
- dataOut << "Ratio of total number of comment lines to the" << endl;
- dataOut << "total number of source code lines: " << commentRatio << endl;;
- dataOut << "Ratio of total number of non-comment lines and" << endl;
- dataOut << "non-blank lines to the total number of source" << endl;
- dataOut << "code lines in file: " << codeRatio << endl;
- }
This is the error I am getting:
c:\documents and settings\matt\my documents\visual studio 2008\projects\assign4\assign4\assign4.cpp(55) : error C2440: '=' : cannot convert from 'std::string' to 'char'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Thanks for any help.