Jump to content

MikeHoward

Member
  • Posts

    1
  • Joined

  • Last visited

Awards

This user doesn't have any awards

MikeHoward's Achievements

  1. My goal is to read the first line of my colors.txt file and assign that integer value to `blue`. However, in my assignment I am instructed to use a char array `red` in order to assist in getting the first line of code. I have succeeded in doing so, but am having trouble with assigning it to `blue`. int main() { ifstream col; char red[50]; int blue = 0; col.open("colors.txt"); col.getline(red, 2, '\n'); cout << "Blue: " << red << endl; } **colors.txt file below** 9 8 7 6 So far I have thought about using the atoi function, but I'm not exactly sure if it will work in this case. Would it work if I copied the character array into the heap and then used a pointer to get the value?
×